C Program To Check Validity of Triangle
Learn How To Check Validity of Triangle in C Programming Language. This is a simple C code that takes in the measures of all the Sides of the Triangle and then checks if a triangle is valid or not using If – Else Block Structure.
As we all know, there are many types of Triangles. Some of them can be of the following types:
- Right Angled Triangle
- Obtuse Triangle
- Acute Triangle
To Find if the Triangle is Valid or not, the Triangle Validity Test includes verifying the following conditions:
- First Side + Second Side > Third Side
- Second Side + Third Side > First Side
- Third Side + First Side > Second Side
A Triangle can be a valid triangle only if the measure of one of the three sides of the triangle is greater than the other two sides.
Also Read: C Program Code To Develop Simple Calculator Application
C Program To Check if the Triangle is Valid or Not
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include<stdio.h> int main() { float side_1, side_2, side_3; printf("\nEnter The First Side\t"); scanf("%f", &side_1); printf("\nEnter The Second Side\t"); scanf("%f", &side_2); printf("\nEnter The Third Side\t"); scanf("%f", &side_3); if ((side_1 + side_2) > side_3) { if((side_1 + side_3) > side_2) { if(side_2 + side_3 > side_1) { printf("\nThe Triangle is a Valid Triangle\n\n"); } else { printf("\nThe Triangle is Not a Valid Triangle\n\n"); } } else { printf("\nThe Triangle is Not a Valid Triangle\n\n"); } } else { printf("\nThe Triangle is Not a Valid Triangle\n\n"); } return 0; } |
Output

Also Read: Code To Print Map of India in C Programming
If you have any doubts or compilation errors in this Code To Check Validity of Triangle in C Programming, you can write about it in the Comment Section below.