第一篇:c語言編程 有一篇文章共有3行文字每行80個(gè)字符要求分別統(tǒng)計(jì)出其中英文字母數(shù)字空
C語言編程 有一篇文章,共有3行文字,每行80個(gè)字符。要求分別統(tǒng)計(jì)出其中英文字母,數(shù)字,空...2種做法,1種用單字符來讀取輸入,1種用字符串來讀取輸入。1.#include
while((c =
if('A' <= c && c <= 'Z')
else if('a' <= c &&
else if('0' <= c
else if(c == upper++;
c <= 'z')lower++;
&& c <= '9')' ')space++;
digit++;
else other++;printf(“upper:%dnlower:%dndigit:%dnspace:%dnother:%dn”, upper, lower, digit, space, other);return 0;} 2.#include
for(j = 0;str[i][j];j++)
gets(str[i]);
if('A' <= str[i][j]
upper++;&& str[i][j] <= 'Z')
else if('a' <= str[i][j] && str[i][j] <= 'z')lower++;
else if('0' <= str[i][j] &&
digit++;
else if(str[i][j] == ' ')str[i][j] <= '9')
space++;
else
other++;}printf(“upper:%dnlower:%dndigit:%dnspace:%dnother:%dn”, upper, lower, digit, space, other);return 0;}提問人的追問
2009-05-02 11:48
“for(j = 0;str[i][j];j++)”這一句沒有限制條件吧!是不是應(yīng)該寫成“for(j=0;str[i][j]!='