Advertisement
BojidarDosev

Input number, output number of digits

Nov 19th, 2023
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int fact(int x)
  5. {
  6.     int br = 0;
  7.     if (x < 10 && x>0)
  8.     {
  9.         return 1;
  10.     }
  11.     else
  12.     {
  13.         while(x>0)
  14.         {
  15.             x / 10;
  16.             br++;
  17.             x = x / 10;
  18.         }
  19.         return br;
  20.     }
  21. }
  22.  
  23. int main()
  24. {
  25.     int x;
  26.     cout << "Enter a num: ";
  27.     cin >> x;
  28.     cout << "Your number cosist of: " << fact(x) << " digits.";
  29.    
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement