fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6.  
  7. int n;
  8. cin>>n;
  9.  
  10. int armNum = 0;
  11. int size = 0;
  12.  
  13. int original = n;
  14.  
  15. //Handle edge case
  16. if(n<=0){
  17. cout<<"Enter valid number: "<<endl;
  18. }
  19.  
  20.  
  21. //find the number of digit in the given number
  22. while(original != 0){
  23. size++;
  24. original = original/10;
  25. }
  26.  
  27. //find the armstrong number;
  28. while(size > 0){
  29. int temp = n%10;
  30. armNum = armNum + temp*temp*temp;
  31. n /= 10;
  32. size--;
  33. }
  34.  
  35. cout<<armNum<<endl;
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5316KB
stdin
123
stdout
36