C语言实现页码数字计数问题 - 统计数字出现次数
#include <stdio.h>
int main() { int n; scanf("%d", &n);
int count[10] = {0}; // 初始化每个数字的计数为0
for (int i = 1; i <= n; i++) {
int num = i;
while (num > 0) {
int digit = num % 10; // 取出最后一位数字
count[digit]++; // 对应数字的计数加1
num /= 10; // 去掉最后一位数字
}
}
for (int i = 0; i < 10; i++) {
printf("%d\n", count[i]);
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/iije 著作权归作者所有。请勿转载和采集!