Skip to content

Commit 1663be0

Browse files
authored
Merge pull request #929 from MathurUtkarsh/patch-2
Create TriangleEverywhere.cpp
2 parents 0bd8ff9 + 86e2b3b commit 1663be0

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* You're given the length of three sides a, b, and c respectively.
2+
Now If these three sides can form an Equilateral Triangle then print 1, if these three sides can form an Isosceles Triangle then print 2,
3+
if these three sides can form a Scalene Triangle then print 3, otherwise print −1.*/
4+
5+
/* Input:
6+
7+
· First-line will contain three numbers a, b, and c separated by space.
8+
9+
Output:
10+
11+
Print the answer in a new line.
12+
13+
Constraints
14+
15+
· 1≤a,b,c≤103
16+
17+
Sample Input 1:
18+
19+
2 4 3
20+
21+
Sample Output 1:
22+
23+
3
24+
25+
Sample Input 2:
26+
27+
4 4 4
28+
29+
Sample Output 2:
30+
31+
1
32+
33+
Sample Input 3:
34+
35+
4 4 9
36+
37+
Sample Output 2:
38+
39+
-1
40+
41+
EXPLANATION:
42+
43+
· In the first example, (2, 4, 3) will form a Scalene Triangle.
44+
45+
· In the second example, (4, 4, 4) will form an Equilateral Triangle.
46+
47+
· In the third example, (4, 4, 9) will not form a triangle.
48+
49+
*/
50+
51+
52+
#include <iostream>
53+
using namespace std;
54+
55+
int main()
56+
{
57+
int a, b, c;
58+
cin >> a >> b >> c;
59+
if (a + b > c && b + c > a && c + a > b) // condition for a triangle.
60+
{
61+
if (a == b && b == c) // condition for equilateral triangle.
62+
cout << "1";
63+
else if (a == b || b == c || c == a) // condition for isosceles triangle.
64+
cout << "2";
65+
else
66+
cout << "3";
67+
}
68+
else
69+
cout << "-1";
70+
return 0;
71+
}

0 commit comments

Comments
 (0)