C言語の例 - 数字が何桁かを判定する
C言語の例
ユーザーが数字を入力し、その数字が何桁かを判定します。
例
#include <stdio.h>
int main()
{
long long n;
int count = 0;
printf("整数を入力してください:");
scanf("%lld", &n);
while(n != 0)
{
n /= 10;
++count;
}
printf("数字は%d桁です。", count);
}
実行結果:
输入一个整数: 2345
数字是 4 位数。
C言語の例
その他の拡張