解题思路:
注意事项:
参考代码:
#include <stdio.h>
int main(void)
{
int i, n, m, digit;
int num[10] = { 0 };
scanf("%d", &n);
for (i = 1;i <= n;i++)
{
m = i;
while (m != 0)
{
digit = m % 10;
m = m / 10;
switch (digit)
{
case 0:
num[0]++;
break;
case 1:
num[1]++;
break;
case 2:
num[2]++;
break;
case 3:
num[3]++;
break;
case 4:
num[4]++;
break;
case 5:
num[5]++;
break;
case 6:
num[6]++;
break;
case 7:
num[7]++;
break;
case 8:
num[8]++;
break;
case 9:
num[9]++;
break;
}
}
}
for (i = 0;i < 10;i++)
{
if (i == 9)
printf("%d", num[i]);
else
printf("%d\n", num[i]);
}
return 0;
}
0.0分
0 人评分