Following is a program to check whether the triangle is valid based on the input lengths of its three sides entered through the keyboard :
Condition: A triangle is considered valid if the sum of any two sides is greater than the largest of the three sides.
#include<stdio.h>
int main(){
float a,b,c,sum,max;
printf("enter the length of sides of triangle: ");
scanf("%f %f %f",&a,&b,&c);
sum= a+b+c;
if(a>b && a>c){
max = a;
}
else if(b>a && b>c){
max = b;
}
if( a+b>max || a+c>max || b+c>max ){
printf("the triangle is valid ");
}
else{
printf("the triangle is not valid ");
}
return 0;
}
Explanation:
The program first takes three sides of the triangle as input.
It calculates the sum of all three sides.
It then determines the maximum side among the three.
The triangle inequality theorem is checked by ensuring that the sum of any two sides is greater than the third side.
The corrected condition sum - max > max is used to check the validity of the triangle. This simplifies the check by ensuring the sum of the other two sides is greater than the maximum side.
Finally, it prints whether the triangle is valid or not.
