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