Untitled
unknown
c_cpp
2 years ago
2.1 kB
5
Indexable
/* ============================================================================ Name : ex_yana_all_points_circle.c Author : Version : Copyright : Your copyright notice Description : Hello World in C, Ansi-style ============================================================================ */ #include <stdio.h> #include <stdlib.h> #include <math.h> // пользователь вводит радиус окружности и координаты её центра на плоскости // программа считывает из файла координаты 10 точек на плоскости // вывести все точки, попадающие в окружность, точки лежащие на границе окружности считаются попавшими в окружность typedef struct Point { int x, y; } Point; void FillArr( FILE *pf, Point arr[ ], const int size ); void PrintAllInCircle( const Point arr[ ], const int size, const int r, const Point c ); double GetDistance( const Point a, const Point b ); int main( void ) { printf( "Введите радиус окружности: " ); int r; scanf( "%d", &r ); printf( "Введите координаты центра окружности: " ); Point c; scanf( "%d%d", &c.x, &c.y ); const int size = 10; FILE *fp = fopen( "points.txt", "r" ); if ( fp == NULL ) { printf( "Open file error!" ); return EXIT_FAILURE; } Point arr[ size ]; FillArr( fp, arr, size ); PrintAllInCircle( arr, size, r, c ); fclose( fp ); return EXIT_SUCCESS; } void FillArr( FILE *pf, Point arr[ ], const int size ) { int i; for ( i = 0; i < size; ++i ) fscanf( pf, "%d%d", &arr[ i ].x, &arr[ i ].y ); } double GetDistance( const Point a, const Point b ) { return sqrt( ( a.x - b.x ) * ( a.x - b.x ) + ( a.y - b.y ) * ( a.y - b.y ) ); } void PrintAllInCircle( const Point arr[ ], const int size, const int r, const Point c ) { int i; for ( i = 0; i < size; ++i ) if ( GetDistance( arr[ i ], c ) < r ) printf( "(%d; %d) ", arr[ i ].x, arr[ i ].y ); }
Editor is loading...