fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4.  
  5. int main()
  6.  
  7. {
  8. int n;
  9. int temp;
  10. int digit;
  11. int count = 0;
  12. int sum = 0;
  13.  
  14.  
  15. scanf("%d", &n);
  16.  
  17. temp = n;
  18.  
  19. while (temp > 0)
  20. {
  21.  
  22.  
  23. count++;
  24.  
  25. temp = temp / 10;
  26.  
  27. }
  28.  
  29.  
  30. temp = n;
  31.  
  32. while (temp >0)
  33.  
  34. {
  35.  
  36. digit = temp % 10;
  37.  
  38. sum = sum + pow(digit, count);
  39.  
  40.  
  41. temp = temp / 10;
  42.  
  43. }
  44.  
  45.  
  46. (sum == n) ?
  47. printf("armstrong number") :
  48. printf("not an armstrong number");
  49.  
  50.  
  51.  
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0s 5320KB
stdin
9 4 7 5
stdout
armstrong number