jasonpogi1669

Calculating the number of digits using log10 function in C++

Dec 15th, 2021 (edited)
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.22 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     ios::sync_with_stdio(false);
  7.     cin.tie(0);
  8.     int n;
  9.     cin >> n;
  10.     int number_of_digits = floor(log10(n)) + 1;
  11.     cout << number_of_digits << '\n';
  12.     return 0;
  13. }
  14.  
Add Comment
Please, Sign In to add comment