Skip to content

luc016.c

Problem Statement

Given the coordiantes (x, y) of center 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. (Hint : Use sqrt() and pow() functions.)

Metadata

Property Detail
Author Amit Dutta amitdutta4255@gmail.com
Date 12 Dec 2025
License MIT License (See the LICENSE file for details)
Difficulty Beginner (index: 1 / 10)

Concepts

Beta Feature

This concept detection system is still in beta and may occasionally show incorrect or incomplete results.

  • Pointers
  • Sorting (possible)
  • Iteration

Actions

Raw View on GitHub

You can print or save this file by opening Raw and using your browser.

Source Code

#include <stdio.h>
#include <math.h>
// Define a small tolerance value (EPSILON) for reliable floating-point comparison
#define EPSILON 0.0001

int main()
{
    double h, k;
    double R;
    double x, y;
    double distance_sq;
    printf("Enter the center coordinates (h, k) : ");
    scanf("%lf %lf", &h, &k);
    printf("Enter the radius (R) : ");
    scanf("%lf", &R);
    printf("Enter the point P coordinates (x, y) : ");
    scanf("%lf %lf", &x, &y);
    distance_sq = pow(x - h, 2) + pow(y - k, 2);
    double radius_sq = R * R;
    // Case 1: On the circle (D^2 = R^2) - Use EPSILON for safety!
    if (fabs(distance_sq - radius_sq) < EPSILON)
    {
        printf("The point P(%g, %g) lies ON THE CIRCLE.\n", x, y);
    }
    // Case 2: Inside the circle (D^2 < R^2)
    else if (distance_sq < radius_sq)
    {
        printf("The point P(%g, %g) lies INSIDE THE CIRCLE.\n", x, y);
    }
    // Case 3: Outside the circle (D^2 > R^2)
    else
    {
        printf("The point P(%g, %g) lies OUTSIDE THE CIRCLE.\n", x, y);
    }
    return 0;
}

Explanation

Explain with AI

Copy the prompt below and paste it into any AI assistant.

    You are explaining a C programming code to a beginner.

    STRICT RULES:

    - Only use the given code. Do NOT assume anything not present.

    - Do NOT add extra examples.

    - Keep explanation clear and short.

    - If something is unclear, say "Not clear from code".

    - Follow the exact format below. Do NOT change headings.

    FORMAT:

    [START]

    ## What it does

    (Explain the overall purpose in 1-2 sentences)

    ## Step-by-step

    (Explain how the code works in steps, simple language)

    ## Key Concepts

    (List concepts like loop, condition, function, etc.)

    ## Notes

    (Mention any limitations, errors, or assumptions)

    [END]

    CODE (luc016.c):

    #include <stdio.h>
    #include <math.h>
    // Define a small tolerance value (EPSILON) for reliable floating-point comparison
    #define EPSILON 0.0001

    int main()
    {
        double h, k;
        double R;
        double x, y;
        double distance_sq;
        printf("Enter the center coordinates (h, k) : ");
        scanf("%lf %lf", &h, &k);
        printf("Enter the radius (R) : ");
        scanf("%lf", &R);
        printf("Enter the point P coordinates (x, y) : ");
        scanf("%lf %lf", &x, &y);
        distance_sq = pow(x - h, 2) + pow(y - k, 2);
        double radius_sq = R * R;
        // Case 1: On the circle (D^2 = R^2) - Use EPSILON for safety!
        if (fabs(distance_sq - radius_sq) < EPSILON)
        {
            printf("The point P(%g, %g) lies ON THE CIRCLE.\n", x, y);
        }
        // Case 2: Inside the circle (D^2 < R^2)
        else if (distance_sq < radius_sq)
        {
            printf("The point P(%g, %g) lies INSIDE THE CIRCLE.\n", x, y);
        }
        // Case 3: Outside the circle (D^2 > R^2)
        else
        {
            printf("The point P(%g, %g) lies OUTSIDE THE CIRCLE.\n", x, y);
        }
        return 0;
    }