Skip to content

luc019.c

Problem Statement

If the length of three sides of a triangle are entered through the keyboard, write a program to check whether the triangle is an isosceles, an equilateral, a scalene or a right-angled triangle.

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

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 EPSILON 0.000001
/* EPSILON is used to compare double values for approximate equality,
mitigating floating-point precision errors. */

int main()
{
    double side1, side2, side3;
    printf("Please enter the length of three side of the triangle : ");
    scanf("%lf %lf %lf", &side1, &side2, &side3);
    if (side1 < 1 || side2 < 1 || side3 < 1)
    {
        printf("\nLength of a side of triangle should be a positive integer.");
        return 1;
    }
    if (side1 + side2 < side3 || side1 + side3 < side2 || side2 + side3 < side1)
    {
        printf("\nEntered triangle is not VALID.");
        return 1;
    }
    // isosceles check
    if (side1 == side2 || side2 == side3 || side3 == side1)
        printf("\nEntered triangle is a ISOSCELES triangle.");
    else
        printf("\nEntered triangle is NOT a ISOSCELES triangle.");
    // equilateral check
    if (side1 == side2 && side2 == side3)
        printf("\nEntered triangle is a EQUILATERAL triangle.");
    else
        printf("\nEntered triangle is NOT a EQUILATERAL triangle.");
    // scalene check
    if (side1 != side2 && side2 != side3)
        printf("\nEntered triangle is a SCALENE triangle.");
    else
        printf("\nEntered triangle is NOT a SCALENE triangle.");
    // right-angle check
    if (fabs(((side1 * side1) + (side2 * side2)) - (side3 * side3)) < EPSILON ||
        fabs(((side2 * side2) + (side3 * side3)) - (side1 * side1)) < EPSILON ||
        fabs(((side3 * side3) + (side1 * side1)) - (side2 * side2)) < EPSILON)
        printf("\nEntered triangle is a RIGHT-ANGLED triangle.");
    else
        printf("\nEntered triangle is NOT a RIGHT-ANGLED triangle.");
    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 (luc019.c):

    #include <stdio.h>
    #include <math.h>

    #define EPSILON 0.000001
    /* EPSILON is used to compare double values for approximate equality,
    mitigating floating-point precision errors. */

    int main()
    {
        double side1, side2, side3;
        printf("Please enter the length of three side of the triangle : ");
        scanf("%lf %lf %lf", &side1, &side2, &side3);
        if (side1 < 1 || side2 < 1 || side3 < 1)
        {
            printf("\nLength of a side of triangle should be a positive integer.");
            return 1;
        }
        if (side1 + side2 < side3 || side1 + side3 < side2 || side2 + side3 < side1)
        {
            printf("\nEntered triangle is not VALID.");
            return 1;
        }
        // isosceles check
        if (side1 == side2 || side2 == side3 || side3 == side1)
            printf("\nEntered triangle is a ISOSCELES triangle.");
        else
            printf("\nEntered triangle is NOT a ISOSCELES triangle.");
        // equilateral check
        if (side1 == side2 && side2 == side3)
            printf("\nEntered triangle is a EQUILATERAL triangle.");
        else
            printf("\nEntered triangle is NOT a EQUILATERAL triangle.");
        // scalene check
        if (side1 != side2 && side2 != side3)
            printf("\nEntered triangle is a SCALENE triangle.");
        else
            printf("\nEntered triangle is NOT a SCALENE triangle.");
        // right-angle check
        if (fabs(((side1 * side1) + (side2 * side2)) - (side3 * side3)) < EPSILON ||
            fabs(((side2 * side2) + (side3 * side3)) - (side1 * side1)) < EPSILON ||
            fabs(((side3 * side3) + (side1 * side1)) - (side2 * side2)) < EPSILON)
            printf("\nEntered triangle is a RIGHT-ANGLED triangle.");
        else
            printf("\nEntered triangle is NOT a RIGHT-ANGLED triangle.");
        return 0;
    }