-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.c
40 lines (36 loc) · 854 Bytes
/
5.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
/*
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.*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#define SUM 1000
int main()
{
int a,b,c;
int i,j,k;
i=1;
while(i)
{ j=i+1;
while(j)
{ k=j+1;
while(i+j+k<=SUM)
{
if((i*i +j*j ==k*k)&&(i+j+k==SUM))
{
printf("%d\t%d\t%d",i,j,k); return 0;
}
k++;
}
if(j+k>SUM)goto avi;
j++;
}
avi:
i++;
}
//return 0;
}