Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //given coordinates(x,y) of a center of circle and its radius, wap which will determine whether a given point lies inside the circle, on the circle, or outside the circle.
- // use pow() and sqrt()
- #include<stdio.h>
- #include<math.h>
- main()
- {
- //declare variables for radius, coordinates, point
- int x1,x2,radius,y1,y2;
- float point, distance;
- printf("Check where the point lies\n");
- printf("--------------------------------\n\n");
- //get input for radius, center coordinates
- printf("Provide the coordinates for circle centre\n");
- printf("x1 : \t");
- scanf("%d",&x1);
- printf("x2 : \t");
- scanf("%d",&y1);
- printf("What is the radius of the circle \n");
- scanf("%d",&radius);
- //get the coordinates to check for
- printf("Provide the point to check for \n");
- printf("p1 : \t");
- scanf("%d",&x2);
- printf("p2 : \t");
- scanf("%d",&y2);
- //print the circle info for clarity
- printf("\nFor The given circle (%d,%d) \n",x1,y1+radius);
- printf("\nAnd the given point (%d,%d) \n",x2,y2);
- //to check where the point lies, we should use the
- //formula, sqrt((x2-x1)*2 + (y2-y1)*2) = r
- distance =(pow((x2-x1),2)+pow((y2-y1),2));
- point = sqrt(distance);
- //check where the point lies
- if(point>radius)
- printf("\nThe point (%d,%d) is outside the circle\n",x2,y2);
- else if(point == radius)
- printf("\nThe point (%d,%d) is on the circle\n",x2,y2);
- else if(point<radius)
- printf("\nThe point (%d,%d) is inside the circle\n",x2,y2);
- }
Add Comment
Please, Sign In to add comment