Example 12: Find the Position of a Point

Learn how to locate the position of a point in the circle.

Problem

Given the coordinates (x, y) of the centre of a circle and its radius, write a program that will determine whether a point lies inside the circle, on the circle, or outside the circle.

The following formulae will help you in the required calculations:

XDifference=centerXpointXX_{Difference}=center_{X}-point_{X}

YDifference=centerYpointYY_{Difference}=center_{Y}-point_{Y}

Distance=(XDifference)2+(YDifference)2Distance=\sqrt{(X_{Difference})^{2}+(Y_{Difference})^{2}}

The output should be printed as a string on the console:

  • outside
  • inside
  • on

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.