fork download
  1. #include <stdio.h>
  2. int countdig(int num)
  3. {
  4. int count=0;
  5. while(num)
  6. {
  7. num=num/10;
  8. count++;
  9. }
  10. return count;
  11. }
  12.  
  13. int powsum(int n,int count)
  14. {
  15. int sum=0;
  16. while(n)
  17. {
  18. int i,prod=1;
  19. for(i=1;i<=count;i++)
  20. {
  21. prod = prod * (n%10);
  22. }
  23. sum = sum+prod;
  24. n = n/10;
  25. }
  26. return sum;
  27. }
  28.  
  29. int main(void) {
  30. int i,a,b;
  31. printf("Enter starting and ending num: \n");
  32. scanf("%d%d",&a,&b);
  33. for(i=a+1;i<b;i++)
  34. {
  35. int count,res;
  36. count = countdig(i);
  37. res = powsum(i,count);
  38. if(res==i)
  39. printf("%d ",i);
  40. }
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0.01s 5292KB
stdin
1 1000
stdout
Enter starting and ending num: 
2 3 4 5 6 7 8 9 153 370 371 407