Home  >  Article  >  Backend Development  >  How to determine how many digits an integer has in C language

How to determine how many digits an integer has in C language

王林
王林Original
2020-05-06 14:37:4618190browse

How to determine how many digits an integer has in C language

Implementation code:

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

where 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 bits of the input number. number.

Recommended tutorial: c language tutorial

The above is the detailed content of How to determine how many digits an integer has in C language. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn