Advertisement
banovski

Project Euler, Problem #9, C

Feb 4th, 2022 (edited)
1,162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. /* A Pythagorean triplet is a set of three natural numbers, a < b < c,
  2.  * for which, a^2 + b^2 = c^2. For example,
  3.  * 3^2 + 4^2 = 9 + 16 = 25 = 5^2. There exists exactly one Pythagorean
  4.  * triplet for which a + b + c = 1000. Find the product abc. */
  5.  
  6. #include <stdio.h>
  7.  
  8. int main()
  9. {
  10.      int x, y, z;
  11.      for(z = 997; z > 2; z--)
  12.           for(y = (999 - z) / 2 + 1; y > 1; y--)
  13.           {
  14.                x = 1000 - (y + z);
  15.                if(x * x + y * y == z * z)
  16.                {
  17.                     printf("%d\n", y * z * x);
  18.                     return(0);
  19.                }
  20.           }
  21. }
  22.  
  23. /* 31875000
  24.  *
  25.  * real 0m0,003s
  26.  * user 0m0,003s
  27.  * sys  0m0,000s */
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement