Guest User

Untitled

a guest
May 3rd, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. /*
  2. A Pythagorean triplet is a set of three natural numbers, a  b  c, for which,
  3.  
  4. a^2 + b^2 = c^2
  5. For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
  6.  
  7. There exists exactly one Pythagorean triplet for which a + b + c = 1000.
  8. Find the product abc.
  9. */
  10.  
  11. #include <stdio.h>
  12.  
  13. int main(void){
  14.  
  15.     int a = 1;
  16.     int b = 1;
  17.     int c = 1;
  18.  
  19.  
  20.     for (int i = 1; i<999; i++){
  21.         a=i;
  22.         for(int j = 1; j<999; j++){
  23.             //printf("A= %d, B= %d\n", i, j);
  24.             b=j;
  25.             c=1000-a-b;
  26.             if((a*a)+(b*b) == c*c){
  27.  
  28.                 printf("%d %d %d\n\n", a,b,c);
  29.                 break;
  30.             }
  31.         }
  32.             if(a*a+b*b == c){
  33.  
  34.                 printf("%d %d %d\n\n", a,b,c);
  35.                 break;
  36.             }
  37.     }
  38.  
  39.     int x = a*b;
  40.     printf("%d %d %d\n\n", a,b,c);
  41.     printf("%d",x);
  42.     return 0;
Advertisement
Add Comment
Please, Sign In to add comment