Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- A Pythagorean triplet is a set of three natural numbers, a b c, for which,
- a^2 + b^2 = c^2
- For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
- There exists exactly one Pythagorean triplet for which a + b + c = 1000.
- Find the product abc.
- */
- #include <stdio.h>
- int main(void){
- int a = 1;
- int b = 1;
- int c = 1;
- for (int i = 1; i<999; i++){
- a=i;
- for(int j = 1; j<999; j++){
- //printf("A= %d, B= %d\n", i, j);
- b=j;
- c=1000-a-b;
- if((a*a)+(b*b) == c*c){
- printf("%d %d %d\n\n", a,b,c);
- break;
- }
- }
- if(a*a+b*b == c){
- printf("%d %d %d\n\n", a,b,c);
- break;
- }
- }
- int x = a*b;
- printf("%d %d %d\n\n", a,b,c);
- printf("%d",x);
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment