fork download
  1. #include <stdio.h>
  2.  
  3. typedef struct Point {
  4. float x,//abscice
  5. y;//ordonate
  6. } TPoint;
  7.  
  8. typedef struct Circle {
  9. TPoint O;
  10. float R;
  11. } TCircle;
  12.  
  13. float sqrt2(float n) {
  14. float x = n,
  15. y = 1.0,
  16. eps = 0.0000001;
  17.  
  18. while(x-y>eps) {
  19. x = (x+y)/2;
  20. y = n / x;
  21. }
  22. return x;
  23. }
  24.  
  25. float sqr(float x) {return x*x;}
  26.  
  27. int main(int argc, char const *argv[]) {
  28.  
  29. float x,y,R,//the circle
  30. x0,y0;//the point
  31. printf("Introduceti Cercul: C(O,R)\n");
  32. scanf("%f %f %f", &x,&y,&R);
  33. printf("Introduceti Point: P(x,y)\n");
  34. scanf("%f %f", &x0,&y0);
  35.  
  36. float dist = sqrt2(sqr(x-x0)+sqr(y-y0));
  37. printf("Distance from the center of the circle to the Point = %f\n",dist);
  38. dist -= R;
  39.  
  40. if(dist < 0) {
  41. printf("%s\n", "The point is inside the Circle.");
  42. } else if(dist == 0) {
  43. printf("%s\n", "The point is on the Circle.");
  44. } else {
  45. printf("%s\n", "The point is outside the Circle.");
  46. }
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0.01s 5388KB
stdin
0 0 2
1 1
stdout
Introduceti Cercul: C(O,R)
Introduceti Point: P(x,y)
Distance from the center of the circle to the Point = 1.414214
The point is inside the Circle.