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=(xp−xc)2+(yp−yc)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 (xp−xc)2+(yp−yc)2 with r2.

Comments

Popular posts from this blog

g

Chapter 5 : Functions & Pointers (Let us C)