Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int Elev(int num, int x);
- int Equal(int num, int numx);
- int Diof(int num);
- int main()
- {
- int NumInput, temp;
- NumInput = temp = 0;
- printf("Introduza um numero: ");
- scanf("%d", &NumInput);
- Diof(NumInput);
- }
- int Elev(int num, int x)
- {
- int temp=1;
- for(;x>0;x--)
- {
- temp *= num;
- }
- return temp;
- }
- int Equal(int num, int numx)
- {
- return (num == numx) ? 1 : 0;
- }
- int Diof(int num)
- {
- int x1, x2, x3, x4;
- x1 = x2 = x3 = x4 = 0;
- for(x1=1;x1<=9;x1++)
- {
- for(x2=x1;x2<=9;x2++)
- {
- if( Equal( Elev(x1, 2) + Elev(x2, 2),num) )
- printf("%d^2 + %d^2 = %d\n", x1, x2, num);
- for(x3=x2;x3<=9;x3++)
- {
- if( Equal( Elev(x1, 2) + Elev(x2, 2) + Elev(x3, 2),num) )
- printf("%d^2 + %d^2 + %d^2 = %d\n", x1, x2, x3, num);
- for(x4=x3;x4<=9;x4++)
- {
- if( Equal( Elev(x1, 2) + Elev(x2, 2) + Elev(x3, 2) + Elev(x4, 2),num) )
- printf("%d^2 + %d^2 + %d^2 + %d^2 = %d\n", x1, x2, x3, x4, num);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement