1. 程式人生 > >一篇短文,有三行文字,每行有80個字元。統計出其中英文大寫字母,小寫字母,數字,空格以及其他字元各有多少。

一篇短文,有三行文字,每行有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;
}