C++ Program to Check if Triangle is Valid or Not using Sides

Write C++ Program to Check if Triangle is Valid or Not using Sides

// CPP Program to Check if Triangle is Valid or Not using Sides

#include <iostream>

using namespace std;

int main()
{
    int side1, side2, side3;

    cout << "Enter Length of Side 1 :--> ";
    cin >> side1;

    cout << "Enter Length of Side 2 :--> ";
    cin >> side2;

    cout << "Enter Length of Side 3 :--> ";
    cin >> side3;

    if((side1 + side2 > side3) &&
       (side2 + side3 > side1) &&
       (side3 + side1 > side2))
    {
        cout << "It is a Valid Triangle";
    }
	else
	{
        cout << "It is an invalid Triangle";
    }

    return 0;
}

Output:

Run - 1:
Enter Length of Side 1 :--> 23
Enter Length of Side 2 :--> 56
Enter Length of Side 3 :--> 98

It is an invalid Triangle

Run - 2:
Enter Length of Side 1 :--> 98
Enter Length of Side 2 :--> 89
Enter Length of Side 3 :--> 74

It is a Valid Triangle

≪ Previous | Next ≫