Advertisement
FoxTuGa

Numeros Divertidos

May 8th, 2011
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define TRUE 1
  4.  
  5. int _elev(float num, int x);
  6.  
  7. int main(void)
  8. {
  9.     int a, b, temp, resto, x;
  10.     int j, sum, sumtemp;
  11.     a = b = temp = resto = sum = sumtemp = 0;
  12.     printf("Introduza dois numeros separados por um <->: ");
  13.     scanf("%d-%d", &a, &b);
  14.  
  15.     if( a < 1 || a > b || b > _elev(2,15) )
  16.     {
  17.         printf("\nERRO\n");
  18.         return 0;
  19.     }
  20.  
  21.     for(x = a; x <= b ; x++)
  22.     {
  23.         for(sum = 0, j = 1;sum < x;j++)
  24.         {
  25.             for(temp = x, sumtemp = 0;temp > 0;)
  26.             {
  27.                 resto = temp % 10;
  28.                 temp /= 10;
  29.  
  30.                 sumtemp += _elev(resto, j);
  31.             }
  32.             if(sumtemp == x)
  33.             {
  34.                 printf(" %7d\n",x);
  35.             }
  36.             if( sum == sumtemp)
  37.                 break;
  38.  
  39.             sum = sumtemp;
  40.         }
  41.     }
  42.     printf("\n\n");
  43.     return 0;
  44. }
  45.  
  46. int _elev(float num, int x)
  47. {
  48.     int temp;  
  49.     for(temp=1;x > 0;x--)
  50.         temp *= num;
  51.     return temp;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement