C Programming Code Examples C > If Else and Switch Case Code Examples program to check whether triangle is valid or not if sides are given program to check whether triangle is valid or not if sides are given Write a C program to input side of a triangle and check whether triangle is valid or not using if else. How to check whether a triangle can be formed or not if sides of triangle is given using if else in C programming. A triangle is valid if sum of its two sides is greater than the third side. Means if a, b, c are three sides of a triangle. Then the triangle is valid if all three conditions are satisfied a + b > c a + c > b and b + c > a Logic to check triangle validity Input sides of a triangle from user. Store them in some variable say side1, side2 and side1. Given triangle is valid if side1 + side2 > side3 and side1 + side3 > side2 and side2 + side3 > side1. #include <stdio.h> int main() { int side1, side2, side3; /* Input three sides of a triangle */ printf("Enter three sides of triangle: \n"); scanf("%d%d%d", &side1, &side2, &side3); if((side1 + side2) > side3) { if((side2 + side3) > side1) { if((side1 + side3) > side2) { /* * If side1 + side2 > side3 and * side2 + side3 > side1 and * side1 + side3 > side2 then * the triangle is valid. */ printf("Triangle is valid."); } else { printf("Triangle is not valid."); } } else { printf("Triangle is not valid."); } } else { printf("Triangle is not valid."); } return 0; }