fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main() {
  5. int num=153, originalNum, remainder, result = 0, n = 0;
  6.  
  7. originalNum = num;
  8.  
  9. // Calculate the number of digits in the number
  10. while (originalNum != 0) {
  11. originalNum /= 10;
  12. n++;
  13. }
  14.  
  15. // originalNum = num;
  16.  
  17. // Calculate the sum of the digits raised to the power of n
  18. while (originalNum != 0) {
  19. remainder = originalNum % 10;
  20. result += pow(remainder, n);
  21. originalNum /= 10;
  22. }
  23.  
  24. // Check if the result equals the original number
  25. if (result == num) {
  26. printf("%d is an Armstrong number.\n", num);
  27. } else {
  28. printf("%d is not an Armstrong number.\n", num);
  29. }
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
153 is not an Armstrong number.