Write the first n (n≤10000) integers sequentially: 123456789101112. Number of 0~9 each occurrence (output 10 integers, respectively, is the number of 0,1,...,9 occurrences).
Note: The idea at first is to write all the 1~10000 into an array, then go through it, and count the number of times the 0~9 appears, which is obviously stupid ...
The correct way to open should be to enter 1~n, each input a number on the statistics once, the number of digits to think about how to separate the bits.
ex3-3.c
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int Main ()
{
int n;
The int s[10];//is used to record the number of 0~9
memset (s,0,sizeof (s)) respectively;
scanf ("%d", &n);
while (n>0)
{
Double num=n;//num is used to isolate the numbers while
(num>=1)
{
int count= (int) num%10
of N; S[count]+=1; The number of statistics as subscript, increased by +1
//printf ("s[%d]=%d\n", Count,s[count]);
NUM=NUM/10;
}
n--;
}
for (int i=0;i<10;i++)
printf ("%d=%d\n", I,s[i]);
return 0;
}