Next
0 / 6
Module DEMO-32-57DEMO-C-32

Point Position Relative to Circle

DEMO-C-32 • Programming in C

Browser-only practice

Problem Statement

Problem Description

Given a circle defined by its center (cx, cy) and radius r, determine the position of a point (px, py) relative to the circle. The point can be either Inside, On, or Outside the circle.

To avoid using the square root function, compare the squared distance from the point to the center of the circle with the square of the radius:

  • If (px - cx)² + (py - cy)² < r², the point is Inside.
  • If (px - cx)² + (py - cy)² = r², the point is On.
  • If (px - cx)² + (py - cy)² > r², the point is Outside.

Examples

  • Input: 0 0 5 3 4 → Output: On
  • Input: 1 1 2 2 3 → Output: Outside

These examples illustrate how to compute the squared distance and compare it to the squared radius.

Constraints

-1000 ≤ cx, cy, px, py ≤ 1000 1 ≤ r ≤ 1000

Input Format

The input consists of five space-separated integers on a single line:

  • cx (integer): x-coordinate of the circle's center
  • cy (integer): y-coordinate of the circle's center
  • r (integer): radius of the circle
  • px (integer): x-coordinate of the point
  • py (integer): y-coordinate of the point

Example: 0 0 5 3 4

Output Format

Output a single string on one line indicating the position of the point:

  • "Inside" if the point is inside the circle
  • "On" if the point lies exactly on the circle
  • "Outside" if the point is outside the circle

There should be no extra spaces or formatting in the output.

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
0
0
5
3
4
On
Distance squared is 3² + 4² = 9 + 16 = 25. Radius squared is 5² = 25. So the point is on the circle.
Sample #2
Public sample
10
10
1
10
11
On
Distance squared is (10-10)² + (11-10)² = 0 + 1 = 1. Radius squared is 1² = 1. So the point is on the circle.
Sample #3
Public sample
1
1
2
2
3
Outside
Distance squared is (2-1)² + (3-1)² = 1 + 4 = 5. Radius squared is 2² = 4. Since 5 > 4, the point is outside.
Sample #4
Public sample
0
0
3
3
3
Outside
Distance squared is 3² + 3² = 9 + 9 = 18. Radius squared is 3² = 9. Since 18 > 9, the point is outside.
Sample #5
Public sample
0
0
5
0
3
Inside
Distance squared is 0² + 3² = 0 + 9 = 9. Radius squared is 5² = 25. Since 9 < 25, the point is inside.
Sample #6
Public sample
5
5
7
6
6
Inside
Distance squared is (6-5)² + (6-5)² = 1 + 1 = 2. Radius squared is 7² = 49. Since 2 < 49, the point is inside.

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings