Advertisement
FoxTuGa

Diofante < Requer +testes>

May 8th, 2011
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int Elev(int num, int x);
  4. int Equal(int num, int numx);
  5. int Diof(int num);
  6.  
  7. int main()
  8. {
  9.     int NumInput, temp;
  10.     NumInput = temp = 0;
  11.  
  12.     printf("Introduza um numero: ");
  13.     scanf("%d", &NumInput);
  14.    
  15.     Diof(NumInput);
  16.  
  17.    
  18. }
  19. int Elev(int num, int x)
  20. {
  21.     int temp=1;
  22.     for(;x>0;x--)
  23.     {
  24.         temp *= num;
  25.     }
  26.     return temp;
  27. }
  28. int Equal(int num, int numx)
  29. {
  30.     return (num == numx) ? 1 : 0;
  31. }
  32. int Diof(int num)
  33. {
  34.     int x1, x2, x3, x4;
  35.     x1 = x2 = x3 = x4 = 0;
  36.    
  37.     for(x1=1;x1<=9;x1++)
  38.     {
  39.         for(x2=x1;x2<=9;x2++)
  40.         {
  41.             if( Equal( Elev(x1, 2) + Elev(x2, 2),num) )
  42.                 printf("%d^2 + %d^2 = %d\n", x1, x2, num);
  43.  
  44.             for(x3=x2;x3<=9;x3++)
  45.             {
  46.                 if( Equal( Elev(x1, 2) + Elev(x2, 2) + Elev(x3, 2),num) )
  47.                         printf("%d^2 + %d^2 + %d^2 = %d\n", x1, x2, x3, num);
  48.  
  49.                 for(x4=x3;x4<=9;x4++)
  50.                 {
  51.                     if( Equal( Elev(x1, 2) + Elev(x2, 2) + Elev(x3, 2) + Elev(x4, 2),num) )
  52.                         printf("%d^2 + %d^2 + %d^2 + %d^2 = %d\n", x1, x2, x3, x4, num);
  53.                 }
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement