C language: Determine the number of digits in a digital integer

#include <stdio.h>
int main()
{
    long long a;
    int count=0;
 
    printf("请输入一个整数:");
    scanf("%lld",&a);
 
    while(a!=0)
    {
     
        a/=10;
        count++;
    }
 
    printf("输入的数字是%d位数。",count);
}

Among them, long long is a long integer and lld is the input method of this type. In this program, count is a counter that records the number of digits entered.

If you have any questions, please comment below and I will answer them for you.

Guess you like

Origin blog.csdn.net/samxiaoguai/article/details/78463095