bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

luc016.c (1522B)


      1 /*
      2  * Author  : Amit Dutta <amitdutta4255@gmail.com>
      3  * Date    : 12 Dec 2025
      4  * Repo    : https://github.com/notamitgamer/bsc
      5  * License : MIT License (See the LICENSE file for details)
      6  */
      7 
      8 /* Given the coordiantes (x, y) of center of a circle and its radius,
      9 write a program that will determine whether a point lies inside the circle,
     10 on the circle or outside the circle. (Hint : Use sqrt() and pow() functions.) */
     11 /* Let Us C, Chap- 3, Page - 53, Qn No.: f(g) */
     12 
     13 #include <stdio.h>
     14 #include <math.h>
     15 // Define a small tolerance value (EPSILON) for reliable floating-point comparison
     16 #define EPSILON 0.0001
     17 
     18 int main()
     19 {
     20     double h, k;
     21     double R;
     22     double x, y;
     23     double distance_sq;
     24     printf("Enter the center coordinates (h, k) : ");
     25     scanf("%lf %lf", &h, &k);
     26     printf("Enter the radius (R) : ");
     27     scanf("%lf", &R);
     28     printf("Enter the point P coordinates (x, y) : ");
     29     scanf("%lf %lf", &x, &y);
     30     distance_sq = pow(x - h, 2) + pow(y - k, 2);
     31     double radius_sq = R * R;
     32     // Case 1: On the circle (D^2 = R^2) - Use EPSILON for safety!
     33     if (fabs(distance_sq - radius_sq) < EPSILON)
     34     {
     35         printf("The point P(%g, %g) lies ON THE CIRCLE.\n", x, y);
     36     }
     37     // Case 2: Inside the circle (D^2 < R^2)
     38     else if (distance_sq < radius_sq)
     39     {
     40         printf("The point P(%g, %g) lies INSIDE THE CIRCLE.\n", x, y);
     41     }
     42     // Case 3: Outside the circle (D^2 > R^2)
     43     else
     44     {
     45         printf("The point P(%g, %g) lies OUTSIDE THE CIRCLE.\n", x, y);
     46     }
     47     return 0;
     48 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror