给出一个整数,计算出该整数有几个数字构成
#include <stdio.h>
int main() {
long long n;
int count = 0;
printf("Enter an integer: ");
scanf("%lld", &n);
// iterate at least once, then until n becomes 0
// remove last digit from n in each iteration
// increase count by 1 in each iteration
do {
n /= 10;
++count;
} while (n != 0);
printf("Number of digits: %d", count);
}
除教程外,本网站大部分文章来自互联网,如果有内容冒犯到你,请联系我们删除!