Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define TRUE 1
- int _elev(float num, int x);
- int main(void)
- {
- int a, b, temp, resto, x;
- int j, sum, sumtemp;
- a = b = temp = resto = sum = sumtemp = 0;
- printf("Introduza dois numeros separados por um <->: ");
- scanf("%d-%d", &a, &b);
- if( a < 1 || a > b || b > _elev(2,15) )
- {
- printf("\nERRO\n");
- return 0;
- }
- for(x = a; x <= b ; x++)
- {
- for(sum = 0, j = 1;sum < x;j++)
- {
- for(temp = x, sumtemp = 0;temp > 0;)
- {
- resto = temp % 10;
- temp /= 10;
- sumtemp += _elev(resto, j);
- }
- if(sumtemp == x)
- {
- printf(" %7d\n",x);
- }
- if( sum == sumtemp)
- break;
- sum = sumtemp;
- }
- }
- printf("\n\n");
- return 0;
- }
- int _elev(float num, int x)
- {
- int temp;
- for(temp=1;x > 0;x--)
- temp *= num;
- return temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement