Software & Finance





Turbo C - Check whether a point is inside or outside the Circle





Here is the Turbo C program to check whether a given point is inside or outside the Circle.

 

The distance between the center of the circle and the given point is calculated first. If the distance is less than or equal to the radius, then the point is inside the circle.

 


Source Code


 

#include <stdio.h>

#include <math.h>

 

 

void main()

{

    int nCountIntersections = 0;

    float x, y, cx, cy, radius;

    float distance;

    printf("Program to find the given point inside or outside the circle:\n");

   

    printf("Enter Center Point - X: ");

    scanf("%f", &cx);

 

    printf("Enter Center Point - Y: ");

    scanf("%f", &cy);

 

    printf("Enter Radius: ");

    scanf("%f", &radius);

 

    printf("Enter Point - X: ");

    scanf("%f", &x);

 

    printf("Enter Point - Y: ");

    scanf("%f", &y);

 

    distance = sqrt( (double)(cx-x)*(cx-x) + (cy-y)*(cy-y));

   

    printf("\nDistance between the point and center of the circle: %.4f", distance);

    if(distance <= radius)

        printf("\nGiven point is inside the circle");

    else

        printf("\nGiven point is outside the circle");

}

Output


 

Program to find the given point inside or outside the circle:

Enter Center Point - X: 10

Enter Center Point - Y: 10

Enter Radius: 7

Enter Point - X: 12

Enter Point - Y: 4

 

Distance between the point and center of the circle: 6.32456

Given point is inside the circle