Write a C++ program to check Triangle Type is Equilateral, Isosceles, or Scalene.
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 36 37 38 39 40 41 42 | #include <iostream> using namespace std; int main() { int a, b, c; int triangleType; cout << "Enter the lengths of the three sides of the triangle:\n"; cout << "Side 1: "; cin >> a; cout << "Side 2: "; cin >> b; cout << "Side 3: "; cin >> c; // Determine the type of the triangle if (a == b && b == c) { triangleType = 1; // Equilateral } else if (a == b || b == c || a == c) { triangleType = 2; // Isosceles } else { triangleType = 3; // Scalene } // Output the type of the triangle switch (triangleType) { case 1: cout << "The triangle is Equilateral.\n"; break; case 2: cout << "The triangle is Isosceles.\n"; break; case 3: cout << "The triangle is Scalene.\n"; break; default: cout << "Invalid triangle type.\n"; break; } return 0; } |
Possible Outputs
Output #1
Enter the lengths of the three sides of the triangle:
Side 1: 5
Side 2: 5
Side 3: 5
The triangle is Equilateral.
Output #2
Enter the lengths of the three sides of the triangle:
Side 1: 5
Side 2: 5
Side 3: 3
The triangle is Isosceles.
Output #3
Enter the lengths of the three sides of the triangle:
Side 1: 4
Side 2: 5
Side 3: 6
The triangle is Scalene.