C program to check whether triangle is equilateral, scalene or isosceles

Write a C program to check whether a triangle is equilateral, scalene or isosceles triangle using if else. Program to enter sides of a triangle and classify triangle as Equilateral, Scalene or Isosceles triangle using if else in C. How to check whether a triangle is equilateral, scalene or isosceles triangle in C programming.

Example:
Input first side: 30
Input second side: 30
Input third side: 30
Output: Equilateral triangle

Required knowledge

Basic programming, If else

Properties of triangle

A triangle is Equilateral Triangle if all its sides are equal.
A triangle is Isosceles Triangle if its two sides are equal.
A triangle is Scalene Triangle if none of its sides are equal.
Read more about properties of triangle.

Program to check equilateral, scalene or isosceles triangle

/**
 * C program to check whether a triangle is Equilateral, Isosceles or Scalene
 */

#include <stdio.h>

int main()
{
    int a, b, c; //a, b, c are three sides of a triangle

    /* Reads all sides of a triangle */
    printf("Enter three sides of triangle: ");
    scanf("%d%d%d", &a, &b, &c);

    if(a==b && b==c) 
    {
        //If all sides are equal
        printf("Equilateral triangle.\n");
    }
    else if(a==b || a==c || b==c) 
    {
        //If two sides are equal
        printf("Isosceles triangle.\n");
    }
    else 
    {
        //If none sides are equal
        printf("Scalene triangle.\n");
    }

    return 0;
} 


Output
Enter three sides of triangle: 30
30
30
Equilateral triangle.

Happy coding ;)


Any doubt or suggestion write here. I will try my best to help. Before posting your code you must escape it to view. To format your source code and use format highlighting, post your source code inside
< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).

No comments:

Post a Comment