-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9pythagorean.c
44 lines (36 loc) · 900 Bytes
/
9pythagorean.c
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
// April 2, 2013
// Project Euler #9
// there is only one pythagorean triplet in which a + b + c = 1000
// find the product of a, and c for this triplet
#include <stdio.h>
#include <stdlib.h>
int
main(void)
{
int a;
int b;
int c;
int x = 0;
// check each combination of a, b, c
for (a = 1; a < 1000; a++)
{
for (b = 1; b < 1000; b++)
{
for (c = 1; c < 1000; c++)
{
if ((a*a)+(b*b) == (c*c) && (a+b+c==1000))
{
x = a*b*c;
break;
}
}
if (x>0)
break;
}
if (x>0)
break;
}
printf("Product of a, b, c in pythagorean in which a + b + c = 1000 is: %d\n", x);
printf("a = %d, b = %d, c = %d\n", a, b, c);
}
// answer: 31,875,000