Statistics on the number of characters in C language and the number of characters in C Language
#include<stdio.h>
int
main()
{
int
sz[10]={0},zm[26]={0},z[26]={0},i,space=0,e=0,t=0;
char
c;
printf
(
"Enter a character to count the number of characters \ n"
);
while
((c=
getchar
())!=
'\n'
)
{
if
(c<=
'z'
&&c>=
'a'
)
zm[c-
'a'
]++;
else
if
(c<=
'Z'
&&c>=
'A'
)
z[c-
'A'
]++;
else
if
(c<=
'9'
&&c>=
'0'
)
sz[c-
'0'
]++;
else
if
(c==
' '
)
space++;
else
e++;
}
printf
(
"\n\n"
);
for
(i=0;i<=9;i++)
{
t++;
printf
(
"% D: % d"
,i,sz[i]);
if
(t%3==0)
printf
(
"\n"
);
}
t=0;
printf
(
"\n\n\n"
);
for
(i=0;i<=25;i++)
{
t++;
printf
(
"% C: % d"
,i+97,zm[i]);
if
(t%3==0)
printf
(
"\n"
);
}
t=0;
printf
(
"\n\n\n"
);
for
(i=0;i<=25;i++)
{
t++;
printf
(
"% C: % d"
,i+65,z[i]);
if
(t%3==0)
printf
(
"\n"
);
}
t=0;
printf
(
"\n\n\n"
);
printf
(
"The number of spaces is % d \ n"
,space);
printf
(
"The number of other characters is % d \ n"
,e);
return
0;
}