C Programming

Solved Example

Practice Questions

Exercise Question

Check a point is inside,outside or on the circle

Objective:

Input the coordinate (x,y) for the center point of a circle and it's the radius. Input coordinate (p,q) for another point and check the point is inside the circle, outside the circle, or on the circle.

Program/Solution:

#include<stdio.h>
#include<math.h>

int main() {
	int x,y;
	int p,q;
	float r,d;
	
	printf("Enter the center point of circle: ");
	scanf("%d %d",&x,&y);
	
	printf("Enter the radius of circle: ");
	scanf("%f",&r);
	
	printf("Enter the other points cordinates: ");
	scanf("%d %d",&p,&q);
	
	//calculate distance between (x,y) and (p,q)
	d = sqrt((x - p) * (x - p) + (y - q) * (y - q));
	
	if(d > r) {
		printf("Point is outside the circle");
	}else if(d < r) {
		printf("Point is inside the circle");
	}else {
		printf("Point is on the circle");
	}
	return 0;
}

Sample Output:

Enter the center point of circle: 5 5
Enter the radius of circle: 10
Enter the other points cordinates: 10 9
Point is inside the circle

More Progarms of Decision Making in C

Calculate profit or loss

Check a number is even or odd

Check a number is positive or negative

Check a year is leap year or not

Find the first day of year

Find the youngest person

Absolute value of a number

Find area of rectangle is greater than perimeter

Check the points are co-linear or not

Check the axis of a point

Identify a character is alphabet, digit and more

Check the insurance eligibility and calculate premium

Calculate the library penalty charges

Calculate grade of a student