189k views
4 votes
Write a C++ programthat returns the type of a triangle (scalene, equilateral,or

isosceles). The input tothe program should consist of the lengths of thetriangle's

3 sides.

1 Answer

3 votes

Answer:

#include<iostream>

using namespace std;

int main(){

//initialize

int a, b,c;

//print the message

cout<<"Enter the three sides of the triangle: "<<endl;

//store in the variables

cin>>a>>b>>c;

//if-else statement for checking the conditions

if(a == b && b == c && a == c){

cout<<"\\The triangle is equilateral";

}else if(a != b && b != c && a != c ){

cout<<"\\The triangle is scalene";

}else{

cout<<"\\The triangle is isosceles";

}

return 0;

}

Step-by-step explanation:

Create the main function and declare the three variables for the length of the sides of the triangle.

print the message on the screen for the user. Then the user enters the values and its store in the variables a, b, and c.

use the if-else statement for checking the conditions.

Equilateral triangle: all sides of the triangle are equal.

if condition true, print the equilateral triangle.

Scalene triangle: all sides of the triangle are not equal.

if condition true, print the Scalene triangle.

if both conditions is not true, then, the program moves to else part and print isosceles.

User Sudee
by
7.9k points