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 ⟨ x c , y c ⟩ and ⟨ x p , y p ⟩ is given by the Pythagorean theorem as d = ( x p − x c ) 2 + ( y p − y c ) 2 − − − − − − − − − − − − − − − − − − √ . The point ⟨ x p , y p ⟩ 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 d 2 with r 2 instead: the point is inside the circle if d 2 < r 2 , on the circle if d 2 = r 2 , and outside the circle if d 2 > r 2 . Thus, you want to compare the number ( x p − x c ) 2 + ( y p − y c ) 2 with...
Comments
Post a Comment