Thursday 25 July 2013

Chapter 2 solutions Problem [C][k]

Question-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.
Solution-fairly a basic mathematics.here is the solution.

#include<stdio.h>
#include<math.h> /*since we are advised to use mathematical terms */
int main()
{
int x,y,p,q;
float r;
printf("Enter the coordinates of center and radius\n");
scanf("%d%d%f",&x,&y,&r);
printf("Enter the coordinates of general point\n");
scanf("%d%d",&p,&q);

if( pow(p-x,2)+pow(q-y,2)>r)
printf("point is outside the circle\n");
else if( pow(p-x,2)+pow(q-y,2)<r)
printf("point is inside the circle\n");
else
printf("point is on the circle\n");
return 0;
}

No comments:

Post a Comment