求正整数的位数

总时间限制:1000ms 内存限制: 65536kB

描述

从键盘输入一个正整数,输出这个正整数的位数。

输入

一个不为0的正整数。

输出

这个正整数的位数。

样例输入

36798

样例输出

5


ac代码

/*
@File     :   get_digits.cpp
@Time     :   2020/04/13
@Desc     :   求正整数的位数
*/
#include <iostream>
#include <stdlib.h>

using namespace std;
unsigned int get_digits(unsigned int n)
{
    if (n < 10) return 1;
    else return get_digits(n/10) + 1;
    
}
int main(int argc, char const *argv[])
{
    unsigned int n;
    cin >> n;
    cout << get_digits(n) << endl;
    system("pause");
    return 0;
}
原文地址:https://www.cnblogs.com/levarz/p/12781576.html