C program to check if the triangle is equilateral, isosceles or scalene triangle


C program to classify triangles as equilateral, isosceles, or scalene based on their side lengths. Explore triangle classification efficiently through C programming.

In the realm of geometry, classifying triangles based on their side lengths is essential. In this article, we'll explore how to create a simple C program that checks whether a triangle is equilateral, isosceles, or scalene.

Understanding Triangle Classification

  • Equilateral Triangle: All three sides of an equilateral triangle are of equal length.
  • Isosceles Triangle: An isosceles triangle has two sides of equal length.
  • Scalene Triangle: A scalene triangle has no sides of equal length.

C program to check if the triangle is equilateral, isosceles or scalene triangle

Let's delve into the C programming language to create a program that classifies a triangle based on its side lengths.

#include <stdio.h>

int main() {
    float side1, side2, side3;

    // Input from the user
    printf("Enter three sides of the triangle: ");
    scanf("%f %f %f", &side1, &side2, &side3);

    // Checking triangle classification
    if (side1 == side2 && side2 == side3) {
        printf("The triangle is an Equilateral Triangle.");
    } else if (side1 == side2 || side1 == side3 || side2 == side3) {
        printf("The triangle is an Isosceles Triangle.");
    } else {
        printf("The triangle is a Scalene Triangle.");
    }

    return 0;
}

Output

Enter three sides of the triangle: 10 10 10
The triangle is an Equilateral Triangle.

Triangle Classification: The program compares the side lengths to determine the type of triangle based on equality between sides.

In this article, we've created a simple C program that efficiently classifies a triangle based on its side lengths. Understanding the concepts of equilateral, isosceles, and scalene triangles through C programming allows us to identify different types of triangles accurately.


Recommended Posts