fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C/C++.
  5. Code, Compile, Run and Debug online from anywhere in world.
  6.  
  7. *******************************************************************************/
  8. #include <iostream>
  9. #include <cmath>
  10. using namespace std;
  11.  
  12. int main() {
  13. int num, originalNum, remainder, n = 0;
  14. double result = 0.0;
  15.  
  16. cout << "Enter an integer: ";
  17. cin >> num;
  18.  
  19. originalNum = num;
  20.  
  21. // Count the number of digits
  22. while (originalNum != 0) {
  23. originalNum /= 10;
  24. ++n;
  25. }
  26.  
  27. originalNum = num;
  28.  
  29. // Calculate the sum of nth powers of its digits
  30. while (originalNum != 0) {
  31. remainder = originalNum % 10;
  32. result += pow(remainder, n);
  33. originalNum /= 10;
  34. }
  35.  
  36. if (result == num)
  37. cout << num << " is an Armstrong number." << endl;
  38. else
  39. cout << num << " is not an Armstrong number." << endl;
  40. cout<<"\n Prachi";
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5324KB
stdin
50
stdout
Enter an integer: 50 is not an Armstrong number.

 Prachi