C Programming Code Examples C > If Else and Switch Case Code Examples C program to check whether triangle is valid or not if angles are given C program to check whether triangle is valid or not if angles are given Write a C program to check whether a triangle is valid or not if angles 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. A triangle is said to be a valid triangle if and only if sum of its angles is 180 degrees. Logic to check triangle validity if angles are given Input all three angles of triangle in some variable say angle1, angle2 and angle3. Find sum of all three angles, store sum in some variable say sum = angle1 + angle2 + angle3. Check if(sum == 180) then, triangle can be formed otherwise not. In addition, make sure angles are greater than 0 i.e. check condition for angles if(angle1 != 0 && angle2 != 0 && angle3 != 0). #include <stdio.h> int main() { int angle1, angle2, angle3, sum; /* Input all three angles of triangle */ printf("Enter three angles of triangle: \n"); scanf("%d%d%d", &angle1, &angle2, &angle3); /* Calculate sum of angles */ sum = angle1 + angle2 + angle3; /* * If sum of angles is 180 and * angle1, angle2, angle3 is not 0 then * triangle is valid. */ if(sum == 180 && angle1 != 0 && angle2 != 0 && angle3 != 0) { printf("Triangle is valid."); } else { printf("Triangle is not valid."); } return 0; }