fork download
  1.  
  2. // Online IDE - Code Editor, Compiler, Interpreter
  3.  
  4. #include<iostream>
  5.  
  6. using namespace std;
  7. int pow_recursive(int p, int q){
  8. if(q==0) return 1;
  9. if(q%2==0){
  10. int result=pow_recursive(p,q/2);
  11. return result*result;
  12. }
  13. else{
  14. int result=pow_recursive(p,(q-1)/2);
  15. return p*result*result;
  16. }
  17. }
  18. int Armstong(int n, int count_zeroes){
  19. if(n==0) return 0;
  20. return pow_recursive(n%10,count_zeroes)+Armstong(n/10,count_zeroes);
  21. }
  22. int main()
  23. { int n;
  24. cout<<"enter the value of n"<<endl;
  25. cin>>n;
  26. int count_zeroes=0;
  27. int d=n;
  28. while(d>0){
  29. d=d/10;
  30. count_zeroes++;
  31. }
  32. int result=Armstong(n,count_zeroes);
  33. if(result==n){
  34. cout<<"YES";
  35.  
  36. }
  37. else{
  38. cout<<"NO";
  39. }
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 5284KB
stdin
45
stdout
enter the value of n
NO