Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created December 28, 2019 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkphp/d070d06c124f6edb8a93b7dad24f2cb6 to your computer and use it in GitHub Desktop.
Save thinkphp/d070d06c124f6edb8a93b7dad24f2cb6 to your computer and use it in GitHub Desktop.
Circle and Point: inside, outside or on the board.
#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