Guest User

Untitled

a guest
Dec 18th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. //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.
  2. // use pow() and sqrt()
  3.  
  4. #include<stdio.h>
  5. #include<math.h>
  6.  
  7. main()
  8. {
  9. //declare variables for radius, coordinates, point
  10. int x1,x2,radius,y1,y2;
  11. float point, distance;
  12. printf("Check where the point lies\n");
  13. printf("--------------------------------\n\n");
  14.  
  15. //get input for radius, center coordinates
  16.  
  17. printf("Provide the coordinates for circle centre\n");
  18. printf("x1 : \t");
  19. scanf("%d",&x1);
  20. printf("x2 : \t");
  21. scanf("%d",&y1);
  22.  
  23. printf("What is the radius of the circle \n");
  24. scanf("%d",&radius);
  25.  
  26. //get the coordinates to check for
  27. printf("Provide the point to check for \n");
  28. printf("p1 : \t");
  29. scanf("%d",&x2);
  30. printf("p2 : \t");
  31. scanf("%d",&y2);
  32.  
  33. //print the circle info for clarity
  34. printf("\nFor The given circle (%d,%d) \n",x1,y1+radius);
  35. printf("\nAnd the given point (%d,%d) \n",x2,y2);
  36.  
  37. //to check where the point lies, we should use the
  38. //formula, sqrt((x2-x1)*2 + (y2-y1)*2) = r
  39.  
  40. distance =(pow((x2-x1),2)+pow((y2-y1),2));
  41. point = sqrt(distance);
  42.  
  43. //check where the point lies
  44. if(point>radius)
  45. printf("\nThe point (%d,%d) is outside the circle\n",x2,y2);
  46. else if(point == radius)
  47. printf("\nThe point (%d,%d) is on the circle\n",x2,y2);
  48. else if(point<radius)
  49. printf("\nThe point (%d,%d) is inside the circle\n",x2,y2);
  50.  
  51.  
  52. }
Add Comment
Please, Sign In to add comment