-
Notifications
You must be signed in to change notification settings - Fork 0
/
09-pitago-1000.cs
63 lines (56 loc) · 1.84 KB
/
09-pitago-1000.cs
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
59
60
61
62
63
namespace pitago
{
class Program
{
// A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
//a2 + b2 = c2
//For example, 32 + 42 = 9 + 16 = 25 = 52.
//There exists exactly one Pythagorean triplet for which a + b + c = 1000.
//Find the product abc.
static void Main(string[] args)
{
// squareC ?
for (int i = 1000; i > 0; i--)
{
int a = i;
for (int j = 1000; j > 0; j--)
{
int b = j;
if (a > b)
break;
for (int k = 1000; k > 0; k--)
{
int c = k;
if (b > c)
break;
int sum = a + b + c;
if (sum == 1000)
{
if (isPytagore(a, b, c))
{
long abc = a * b * c;
System.Console.WriteLine("product a = {0}", a);
System.Console.WriteLine("product b = {0}", b);
System.Console.WriteLine("product c = {0}", c);
System.Console.WriteLine("product abc = {0}", abc);
break;
}
}
}
}
}
System.Console.ReadLine();
}
public static bool isPytagore(int a, int b, int c)
{
int squareA = a * a;
int squareB = b * b;
int squareC = c * c;
if (squareC == (squareA + squareB))
{
return true;
}
return false;
}
}
}