有一篇短文,共有3行文字,每行有80个字符。想统计出其中英文大写字母,小写字母,数字,空格以及其他字符各有多少个。
#include<stdio.h>
#include<cstring>
int main()
{
char a[3][80];
char c;
int i, j, up = 0, low =
0, digit = 0, space = 0, other = 0;//定义变量
printf("请输入3:\n");
for (i = 0; i < 3;
i++)
{
gets_s(a[i]);//输入文字
{
for (j = 0; j < 80
&& ((c = a[i][j]) != '\0'); j++)
{
if (c >= 'A' && c <= 'Z')
up++;
else if
(c
>= 'a'
&& c <= 'z')
low++;
else if
(c
>= '0'&&
c <='9')
digit++;
else if
(c
== ' ')
space++;
else
other++;
}
}
}
printf("大写字母:%d\n", up);
printf("小写字母:%d\n", low);
printf("数字:%d\n", digit);
printf("空格:%d\n", space);
printf("其他:%d\n", other);
return 0;
}