Dremendo Tag Line

Input angles and check equilateral, isosceles, or scalene triangle in C

if else if - Question 8

In this question, we will see how to input 3 angles of a triangle and check whether it is an equilateral, isosceles or scalene triangle in C programming using the if else if statement. To know more about if else if statement click on the if else if statement lesson.

Q8) Write a program in C to input 3 angles of a triangle and check whether it is an equilateral, isosceles or scalene triangle.

An equilateral triangle is one whose all angles are equal and the sum of all the angles is 180. An isosceles triangle is one whose any two angles are equal and the sum of all the angles is 180. A scalene triangle is one whose none of the angles are equal but sum of all the angles is 180.

Program

#include <stdio.h>
#include <conio.h>

int main()
{
    int a,b,c;
    printf("Enter 3 angles of a triangle\n");
    scanf("%d%d%d",&a,&b,&c);
    if(a+b+c==180)
    {
        if(a==b && b==c && c==a)
        {
            printf("Equilateral triangle");
        }
        else if(a==b || b==c || c==a)
        {
            printf("Isosceles triangle");
        }
        else
        {
            printf("Scalene  triangle");
        }
    }
    else
    {
        printf("Invalid input");
    }
    return 0;
}

Output

Enter 3 angles of a triangle
45
90
45
Isosceles triangle           
video-poster