如何判断一个数是几位数?不转换成字符串也不循环还有其它做法么?

这是我的程序,请大侠看看

 #include <iostream>

using namespace std;

int jiweishu(int n);

int main()
{
    int a;
    cin >> a;
    cout << jiweishu(a);
}

int jiweishu(int n)
{
    int ws = 0;
    while (n > 0)
    {
        n /= 10;
        ws++;
    }
    return ws;
}

没念过初中?不知道Log?

 #include <math.h>
#include <iostream>

using namespace std;

int jiweishu(int n);

int main()
{
    int a;
    cin >> a;
    cout << jiweishu(a);
}

int jiweishu(int n)
{
    return (int)log10(n) + 1;
}

判断length,根据长度就知道几位数了