luc016.c ​
Metadata ​
- Author — Amit Dutta
- Last updated — 12 Dec 2025
- License — MIT License (See the LICENSE file for details)
Problem Statement ​
Problem Statement
Given the coordiantes (x, y) of center of a circle and its radius, write a program that will determine whether a point lies inside the circle, on the circle or outside the circle. (Hint : Use sqrt() and pow() functions.)
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include <stdio.h>
#include <math.h>
// Define a small tolerance value (EPSILON) for reliable floating-point comparison
#define EPSILON 0.0001
int main()
{
double h, k;
double R;
double x, y;
double distance_sq;
printf("Enter the center coordinates (h, k) : ");
scanf("%lf %lf", &h, &k);
printf("Enter the radius (R) : ");
scanf("%lf", &R);
printf("Enter the point P coordinates (x, y) : ");
scanf("%lf %lf", &x, &y);
distance_sq = pow(x - h, 2) + pow(y - k, 2);
double radius_sq = R * R;
// Case 1: On the circle (D^2 = R^2) - Use EPSILON for safety!
if (fabs(distance_sq - radius_sq) < EPSILON)
{
printf("The point P(%g, %g) lies ON THE CIRCLE.\n", x, y);
}
// Case 2: Inside the circle (D^2 < R^2)
else if (distance_sq < radius_sq)
{
printf("The point P(%g, %g) lies INSIDE THE CIRCLE.\n", x, y);
}
// Case 3: Outside the circle (D^2 > R^2)
else
{
printf("The point P(%g, %g) lies OUTSIDE THE CIRCLE.\n", x, y);
}
return 0;
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36