Write a C program to check whether triangle is valid or not if all angles of the triangle are given using if else. How to check whether a triangle can be formed or not if its angles are given using if else in C programming. Program to check a valid triangle based on its angles in C.

Input first angle: 60

Input second angle: 30

Input third angle: 90

Output: Triangle is valid.

Formula: a + b + c = 180° (Where a, b, c are three angles of a triangle).

Happy coding ;)

**Example:**Input first angle: 60

Input second angle: 30

Input third angle: 90

Output: Triangle is valid.

### Required knowledge

Basic C programming, If else#### Property of a triangle

We know that a triangle is valid if and only if sum of all three angles is 180°. Read more about properties of triangle.Formula: a + b + c = 180° (Where a, b, c are three angles of a triangle).

### Program to check valid triangle

/** * C program to check whether a triangle is valid or not if angles are given */ #include <stdio.h> int main() { int a, b, c, sum; //a, b, c are three angles of a triangle /* Reads all three angles of triangle */ printf("Enter three angles of triangle: \n"); scanf("%d%d%d", &a, &b, &c); /* Calculate the sum of all angles of triangle */ sum = a + b + c; /* If sum=180 then its a valid triangle else not */ if(sum == 180) { printf("Triangle is valid.\n"); } else { printf("Triangle is not valid.\n"); } return 0; }

Output

Enter three angles of triangle:

30

60

90

Triangle is valid.

30

60

90

Triangle is valid.

Happy coding ;)

### You may also like

- If else programming exercises index.
- C program to check whether a triangle is valid or not is its sides are given.
- C program to check whether a triangle is Equilateral, Isosceles or Scalene triangle.
- C program to find angle of a triangle if two angles of the triangle are given.
- C program to find area of a triangle.
- C program to calculate area of an Equilateral triangle.
- C program to enter two angles of a triangle and find third angle.
- C program to enter any number and check whether the number is even or odd.
- C program to enter year and check whether it is leap year or not.
- C program to enter any number and check whether it is negative, zero or positive.
- C program to check whether a character is alphabet, digit or any special character.
- C program to enter any number and check whether it is divisible by 5 and 11 or not.

< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).