Home > Backend Development > C#.Net Tutorial > How to determine how many digits an integer has in C language

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

王林
Release: 2020-05-06 14:37:46
Original
18297 people have browsed it

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);
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template