WAP to input the sides of a triangle and check whether the triangle is possible or not if possible then display whether it is equilateral isosceles or a scalene triangle otherwise display triangle is not possible
Home
/
Computer Science
/
WAP to input the sides of a triangle and check whether the triangle is possible or not if possible then display whether it
Verified answer
Here I'm using C++ programming language for writing the program as you've not clearly mentioned any.#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int a, b, c;
cin >> a >> b >> c;
// check whether a, b, c can form a possible triangle
if (a+b > c && a+c > b && b+c > a)
cout << "The triangle is possible.\n";
// To check whether the triangle is equilateral, isosceles, or scalene.
if (a==b && b==c) // all sides equal
cout << "Equilateral triangle\n";
else if (a==b || a==c || b==c) // at least 2 sides equal
cout << "Isosceles triangle\n";
else // no sides equal
cout << "Scalene triangle\n";
else
cout << "The triangle isn't possible.\n";
return 0;
}