wohyperion

The number of digits

Jun 27th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. int digits(int num)
  4. {
  5.     int amount = 0;
  6.     while (num != 0)
  7.     {
  8.         num /= 10;
  9.         amount++;
  10.     }
  11.     return amount;
  12. }
  13.  
  14. int main()
  15. {
  16.     int num;
  17.     std::cout << "Input number: ";
  18.     std::cin >> num;
  19.     std::cout << "The number of digits: " << digits(num) << std::endl;
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment