Repository navigation
Expand file tree
/
Copy pathtrianglesfunction.cpp
More file actions
58 lines (53 loc) · 1.5 KB
/
Copy pathtrianglesfunction.cpp
File metadata and controls
58 lines (53 loc) · 1.5 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*Write a C++ program that determines the type of a triangle based on the lengths of its three sides.
The program should prompt the user to enter three integer values representing the side lengths.
Based on these inputs, it should classify and output the type of triangle as one of the following:
• Equilateral Triangle: All three sides are equal.
• Isosceles Triangle: Exactly two sides are equal.
• Scalene Triangle: All three sides are different.
• Invalid Triangle: The sum of the lengths of any two sides must be greater than the length of
the third side. If this condition is not met, the input does not form a valid triangle.
Additionally, determine if possible, whether the triangle is right triangle using Pythagoras*/
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
bool valid(int a, int b, int c)
{
return (a+b>c && b+c>a && c+a>b);
}
string type(int a,int b,int c)
{
if(a==b && b==c){
return "Equilateral Triangle";
}
else if(a==b ||b==c || c==a){
return"isoceles Triangle";
}
else{
return "scalene Triangle";
}
}
bool RHD(int a, int b,int c){
if(a*a+b*b==c*c || b*b+c*c==a*a || c*c+a*a==b*b){
return "right angle Triangle";
}
}
int main(){
int a,b,c;
cout<<"Enter three values: "<<endl;
cin>>a>>b>>c;
if(!(valid(a,b,c))){
cout<<"no valid triangle."<<endl;
}
else{
cout<<valid(a,b,c)<<endl;
}
cout<<type(a,b,c)<<endl;
if(RHD(a,b,c)){
cout<<"it's a right angle triangle."<<endl;
}
else{
cout<<"not a right angle trianle."<<endl;
}
return 0;
}