In this C program, we will learn about how to check whether a triangle is valid or not given the length of three sides of triangle. A triangle is a valid triangle, If and only If, the sum of any two sides of a triangle is greater than the third side.
For Example, let A, B and C are three sides of a triangle. Then, A + B > C, B + C > A and C + A > B.
Required Knowledge
C program to check whether a triangle is valid, given sides of triangle
#include <stdio.h>
int main() {
int side1, side2, side3;
printf("Enter Length of Sides of a Triangle\n");
scanf("%d %d %d", &side1, &side2, &side3);
if((side1 + side2 > side3)&&(side2 + side3 > side1)
&&(side3 + side1 > side2)) {
printf("It is a Valid Triangle\n");
} else {
printf("It is an invalid Triangle");
}
return 0;
}
Output
Enter Length of Sides of a Triangle 10 20 20 It is a Valid Triangle
Enter Length of Sides of a Triangle 10 20 40 It is an invalid Triangle
Related Topics