Created
December 28, 2019 09:00
-
-
Save thinkphp/d070d06c124f6edb8a93b7dad24f2cb6 to your computer and use it in GitHub Desktop.
Circle and Point: inside, outside or on the board.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
struct TPoint { | |
float x, | |
y; | |
}; | |
typedef struct TPoint Point; | |
struct TCircle { | |
Point O; | |
float r; | |
}; | |
typedef struct TCircle Circle; | |
int main(int argc, char const *argv[]) | |
{ | |
Circle C; | |
Point P; | |
double d; | |
printf("%s\n", "Circle -> "); | |
scanf("%f %f %f", &C.O.x, &C.O.y, &C.r); | |
printf("%s\n", "Point -> "); | |
scanf("%f %f", &P.x, &P.y); | |
d = sqrt((P.x - C.O.x) * (P.x - C.O.x) + (P.y - C.O.y) * (P.y - C.O.y)); | |
d -= C.r; | |
if( d == 0) { | |
printf("%s\n", "The Point is on the board of the Circle."); | |
} else if( d < C.r) { | |
printf("%s\n", "The Point is inside of the Circle."); | |
} else if(d > C.r) { | |
printf("%s\n", "The Point is outside of the Circle."); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment