Coding Practice

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

Check Equilateral, Isosceles or Scalene Triangle
Sample Output
Enter three sides...
4
4
5

The triangle is isosceles.

Process returned 0 (0x0)   execution time : 4.104 s
Press any key to continue.
Source Code
#include<stdio.h>

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

    printf("Enter three sides...\n");
    scanf("%d %d %d", &side1, &side2, &side3);

    if(side1 + side2 > side3 && side1 + side3 > side2 && side2 + side3 > side1)
    {
        if(side1 == side2 && side2 == side3)
        {
            printf("\nThe triangle is equilateral.\n");
        }
        else if(side1 == side2 || side2 == side3 || side1 ==side3)
        {
            printf("\nThe triangle is isosceles.\n");
        }
        else
        {
            printf("\nThe triangle is scalene.\n");
        }
    }
    else
    {
        printf("\nThe triangle is not valid.\n");
    }
    return 0;
}
Sample Output
Enter three sides...
5
6
7

The triangle is scalene.

Process returned 0 (0x0)   execution time : 2.203 s
Press any key to continue.

No comments:

Post a Comment

Change Theme
X