一篇短文,有三行文字,每行有80个字符。统计出其中英文大写字母,小写字母,数字,空格以及其他字符各有多少。

一篇短文,有三行文字,每行有80个字符。统计出其中英文大写字母,小写字母,数字,空格以及其他字符各有多少。
#include<stdio.h>
int main()
{
int i, j,a,b,c,w,other;
//int a = 0; int b = 0; int c = 0; int s= 0;int other = 0;
a = b = c = s = other = 0;
char str[3][80] = {’\0’};
printf(“请输入三行文字:\n”);
for (i = 0; i < 3; i++)
{
gets_s(str[i]);//每一行
for (j = 0; (str[i][j]) != ‘\n’&& j < 80; j++)
{
if (str[i][j] >= ‘A’ && str[i][j] <= ‘Z’)
a++;
else if (str[i][j] >= ‘a’ && str[i][j] <= ‘z’)
b++;
else if (str[i][j] >=0 && str[i][j] >= 9)
c++;
else if (str[i][j]==’’)
s++;
else
other++;
}
}
printf(“这三行文字中有:\n”);
printf(“大写字母:%d\n”, a);
printf(“小写字母:%d\n”, b);
printf(“数字:%d\n”, c);
printf(“空格:%d\n”, s);
printf(“其他字符:%d\n”, other);
return 0;
}

猜你喜欢

转载自blog.csdn.net/sinat_39154965/article/details/84423749
今日推荐