This code calculates the number of digits of the number which we enter depending on that you always get less than 1 if you divide a number by a number that has one digit more; the program still divides until it gets less than one.
I tried to define num
as long integer.
#include <iostream>
#include <cmath>
using namespace std;
int main () {
int num,n,dev;
dev = 10;
n = 1;
cin >> num;
double dn = num / dev;
if (dn < 1){
cout << n;
}
if (dn >= 1){
while (dn >= 1){
dev *= 10;
dn = num / dev;
n++;
}
cout << n;
}
return 0;
}
I expect that it will work on all digits.