Advertisement
193030

ArmStrong number check

Jun 17th, 2021
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. void ArmStrongNumberCheck(int input)
  8. {
  9.     string tempStr = to_string(input);
  10.     int digits = tempStr.size();
  11.     digits;
  12.     double sum = 0;
  13.     for(int i =0; i< digits;i++)
  14.     {
  15.         int tempNumber = tempStr.at(i) - 48;
  16.         sum = sum + pow(tempNumber, digits);
  17.     }
  18.     cout << sum << endl;
  19.     if(sum == input)
  20.     {
  21.         cout << "True" << endl;
  22.     }
  23.     else
  24.     {
  25.         cout << "False" << endl;
  26.     }
  27. }
  28.  
  29. int main()
  30. {
  31.     int input = 153;
  32.     ArmStrongNumberCheck(input);
  33.    
  34.    
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement