C Program to Check Whether a Triangle is Valid or Not given Sides of Triangle

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
C program to check whether three angles of triangle is valid or not
C Program to Check Whether a Triangle is Equilateral, Isosceles or Scalene Triangle
C Program to Calculate Area of a Right Angled Triangle
C Program to Calculate Area of Any Triangle using Heron's Formula
C Program to Find Third Angle of a Triangle
C Program to Print Floyd's Triangle
C Program to Print Triangle and Pyramid patterns of Star(*) Character Using Loop
C Program to Print Pascal Triangle till N Rows
C Program to Calculate Area and Perimeter of an Equilateral Triangle
List of all C programs