Two special kinds of triangles are equilateral triangles and right triangles: In
ID: 3668008 • Letter: T
Question
Two special kinds of triangles are equilateral triangles and right triangles: In an equilateral triangle, all three sides have the same length. In a right triangle, the square of the length of one side is equal to the sum of the squares of the lengths of the other two sides. Write a program that prompts the user to enter the lengths of a triangle's sides, and then displays a message saying whether the triangle is equilateral, right, or neither. The user may enter the lengths of the three sides in any order-or example, do not assume that the user will enter the shortest side first and the longest side last Three sample runs are shown below. Your prompts and outputs should look exactly like these, including spelling, punctuation, capitalization, spacing, and number format.Explanation / Answer
#include <bits/stdc++.h>
using namespace std;
int isEquilateral(double a, double b, double c){
return ((a==b) && (a==c));
}
int isRightAngled(double a, double b, double c){
a = a*a;
b = b*b;
c = c*c;
return ((a=(b+c)) || (b=(a+c)) || (c=(a+b)));
}
int main(){
cout << "Enter the lengths of the triangle's sides: ";
double a,b,c;
cin >> a >> b >> c ;
printf("A triangle with sides %.2f, %.2f, %.2f is ", a, b, c);
if(isEquilateral(a,b,c)){
cout << "an equilateral triangle. ";
}
else if(isRightAngled(a,b,c)){
cout << "a right triangle. ";
}
else{
cout << "neither equilateral nor right.";
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.