luc016.c (1331B)
1 /* Given the coordiantes (x, y) of center of a circle and its radius, 2 write a program that will determine whether a point lies inside the circle, 3 on the circle or outside the circle. (Hint : Use sqrt() and pow() functions.) */ 4 /* Let Us C, Chap- 3, Page - 53, Qn No.: f(g) */ 5 6 #include <stdio.h> 7 #include <math.h> 8 // Define a small tolerance value (EPSILON) for reliable floating-point comparison 9 #define EPSILON 0.0001 10 11 int main() 12 { 13 double h, k; 14 double R; 15 double x, y; 16 double distance_sq; 17 printf("Enter the center coordinates (h, k) : "); 18 scanf("%lf %lf", &h, &k); 19 printf("Enter the radius (R) : "); 20 scanf("%lf", &R); 21 printf("Enter the point P coordinates (x, y) : "); 22 scanf("%lf %lf", &x, &y); 23 distance_sq = pow(x - h, 2) + pow(y - k, 2); 24 double radius_sq = R * R; 25 // Case 1: On the circle (D^2 = R^2) - Use EPSILON for safety! 26 if (fabs(distance_sq - radius_sq) < EPSILON) 27 { 28 printf("The point P(%g, %g) lies ON THE CIRCLE.\n", x, y); 29 } 30 // Case 2: Inside the circle (D^2 < R^2) 31 else if (distance_sq < radius_sq) 32 { 33 printf("The point P(%g, %g) lies INSIDE THE CIRCLE.\n", x, y); 34 } 35 // Case 3: Outside the circle (D^2 > R^2) 36 else 37 { 38 printf("The point P(%g, %g) lies OUTSIDE THE CIRCLE.\n", x, y); 39 } 40 return 0; 41 }