題目:輸入一行字符,分別統(tǒng)計出其中英文字母、空格、數(shù)字和其它字符的個數(shù)。
1.程序分析:利用while語句,條件為輸入的字符不為'\n'.
2.程序源代碼:
#include "stdio.h"
main()
{char c;
int letters=0,space=0,digit=0,others=0;
printf("please input some characters\n");
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else
others++;
}
printf("all in all:char=%d space=%d digit=%d others=%d\n",letters,
space,digit,others);
}
相關(guān)推薦:
2009年9月計算機(jī)等考二級ACCESS模擬試題匯總 考試吧:2010年計算機(jī)等考二級C預(yù)測題匯總 計算機(jī)等級考試二級JAVA考前密卷二套(1)