问题一百五十九:正整数解

最好不要用函数pow();我一开始就错在这函数上!

 

  1. #include <stdio.h>
  2. int main()
  3. {
  4.     int x;
  5.     int y;
  6.     int z;
  7.     int flag;
  8.     int num;
  9.     while(scanf(“%d”, &num)!=EOF && (num>0 && num<=10000))
  10.     {
  11.         flag=0;
  12.          for(x=1; x*x<num; x++)
  13.          {
  14.              for(y=1; y*y<num; y++)
  15.              {
  16.                 for(z=1; z*z<num; z++)
  17.                 {
  18.                     if(x*x+ y*y +z*z==num && (x<=y && y<=z))
  19.                     {
  20.                         printf(“%d %d %d\n”, x, y, z);
  21.                         flag=1;
  22.                         break;
  23.                     }
  24.                 }
  25.                 if(flag)
  26.                 {
  27.                    break;
  28.                 }
  29.              }
  30.              if(flag)
  31.                 {
  32.                    break;
  33.                 }
  34.          }
  35.     }
  36.     return 0;
  37. }

结果图:

 

 

标签