Write a C++ Program to Check Triangle is Valid using Sides by using If else statement with an example.
#include<iostream> using namespace std; int main() { int side1, side2, side3; cout << "\nPlease Enter Three Sides of a Triangle = "; cin >> side1 >> side2 >> side3; if( (side1 + side2 > side3) && (side2 + side3 > side1) && (side1 + side3 > side2) ) { cout << "\nThis is a Valid Triangle"; } else cout << "\nThis is an Invalid Triangle"; return 0; }
OUTPUT 2
Please Enter Three Sides of a Triangle = 20 40 50
This is a Valid Triangle
C++ Program to Check Triangle is Valid using Sides Example 2
#include<iostream> using namespace std; int main() { int side1, side2, side3; cout << "\nPlease Enter Three Sides of a Triangle = "; cin >> side1 >> side2 >> side3; if(side1 + side2 > side3) { if(side2 + side3 > side1) { if(side1 + side3 > side2) { cout << "\nThis is a Valid Triangle"; } else { cout << "\nThis is an Invalid Triangle"; } } else { cout << "\nThis is an Invalid Triangle"; } } else cout << "\nThis is an Invalid Triangle"; return 0; }
Please Enter Three Sides of a Triangle = 25 65 56
This is a Valid Triangle
C++ Program to find Triangle is Valid using Sides Example 3
#include<iostream> using namespace std; int main() { int side1, side2, side3, flag = 0; cout << "\nPlease Enter Three Sides of a Triangle = "; cin >> side1 >> side2 >> side3; if(side1 + side2 > side3) { if(side2 + side3 > side1) { if(side1 + side3 > side2) { flag = 1; } } } if(flag == 1) { cout << "\nThis is a Valid Triangle"; } else { cout << "\nThis is an Invalid Triangle"; } return 0; }
Please Enter Three Sides of a Triangle = 7 5 6
This is a Valid Triangle