1#include <iostream>
2#include <cmath>
3
4unsigned int getNumberOfDigits (int i)
5{
6 return i > 0 ? log10((double) i) + 1 : 1;
7}
8
9int main()
10{
11 std::cout << "Number of digits: " << getNumberOfDigits(/*Example*/6738) << std::endl;
12 return 0;
13}
1n = 1234 //Any Random Number
2digits = len(str(n)) //Saves the number of digits of n into the variable digits