-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02)number_counter_machine.c
51 lines (51 loc) · 1.11 KB
/
02)number_counter_machine.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
int main() {
int c0=0,c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c7=0,c8=0,c9=0,i;
char *s;
s = malloc(1001*sizeof(char));
scanf("%[^\n]",s);
s = realloc(s, strlen(s)+1);
for(i=0;i<strlen(s);i++)
{
switch (s[i]) {
case '0':
c0++;
break;
case '1':
c1++;
break;
case '2':
c2++;
break;
case '3':
c3++;
break;
case '4':
c4++;
break;
case '5':
c5++;
break;
case '6':
c6++;
break;
case '7':
c7++;
break;
case '8':
c8++;
break;
case '9':
c9++;
break;
default:
break;
}
}
printf("%d %d %d %d %d %d %d %d %d %d",c0,c1,c2,c3,c4,c5,c6,c7,c8,c9);
return 0;
}