Given the coordinates (x, y) of a center of a circle and it’s radius, write a program which will determine whether a point lies inside the circle, on the circle or outside the circle.

C Programm:

#include<stdio.h>
main()
{
int x,y,r;
int di,ra;
printf("Enter the value of x and y:");
scanf("%d %d",&x,&y);
printf("Enter the radius:");
scanf("%d",&r);
di=x^2+y^2;
ra=r^2;
if(di==r)
printf("Point on the Circle");
else if(di>r)
printf("Point outside the Circle");
else if(di<r)
printf("Point inside the Circle");
}

Math:The distance between xc,yc and xp,yp is given by the Pythagorean theorem as

d=(xpxc)2+(ypyc)2.
The point xp,yp is inside the circle if d<r, on the circle if d=r, and outside the circle if d>r. You can save yourself a little work by comparing d2 with r2 instead: the point is inside the circle if d2<r2, on the circle if d2=r2, and outside the circle if d2>r2. Thus, you want to compare the number (xpxc)2+(ypyc)2 with r2.

Comments

Popular posts from this blog

Chapter 5 : Functions & Pointers (Let us C)

According to a study, the approximate level of intelligence of a person can be calculated using the following formula: i = 2 + ( y + 0.5 x ) Write a program, which will produce a table of values of i, y and x, where y varies from 1 to 6, and, for each value of y, x varies from 5.5 to 12.5 in steps of 0.5.

Let Us C / Chapter 4 (The Case Control Structure)