一篇短文,有三行文字,每行有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;
}
本文介绍了一个使用C语言编写的程序,该程序能够统计输入的三行文字中大写和小写字母、数字、空格以及其他字符的数量。通过逐行读取和遍历字符串,程序有效地实现了字符类型的分类计数。

被折叠的 条评论
为什么被折叠?



