-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpythagorean_triple.cpp
27 lines (18 loc) · 1016 Bytes
/
pythagorean_triple.cpp
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
//Given an unsorted array of 3 positive integers [ n1, n2, n3 ], determine if it is possible to form a Pythagorean Triple using those 3 integers.
//A Pythagorean Triple consists of arranging 3 integers, such that:
//a2 + b2 = c2
//Examples
//[5, 3, 4] : it is possible to form a Pythagorean Triple using these 3 integers: 32 + 42 = 52
//[3, 4, 5] : it is possible to form a Pythagorean Triple using these 3 integers: 32 + 42 = 52
//[13, 12, 5] : it is possible to form a Pythagorean Triple using these 3 integers: 52 + 122 = 132
//[100, 3, 999] : it is NOT possible to form a Pythagorean Triple using these 3 integers - no matter how you arrange them, you will never find a way to satisfy the equation a2 + b2 = c2
//Return Values
// For Python: return True or False
// For JavaScript: return true or false
// Other languages: return 1 or 0 or refer to Sample Tests.
bool PythagoreanTriple(const int a, const int b, const int c)
{
if (a * a + b * b == c * c)
return true;
return false;
}