7-90 統計字符 (15分)


7-90 統計字符 (15分)
 

本題要求編寫程序,輸入10個字符,統計其中英文字母、空格或回車、數字字符和其他字符的個數。

輸入格式:

輸入為10個字符。最后一個回車表示輸入結束,不算在內。

輸出格式:

在一行內按照

letter = 英文字母個數, blank = 空格或回車個數, digit = 數字字符個數, other = 其他字符個數 
 

的格式輸出。

輸入樣例:

aZ &
09 Az
 

輸出樣例:

letter = 4, blank = 3, digit = 2, other = 1



#include<stdio.h>
#include<string.h>
int main()
{
 char c;
 int count=0;
 int letter=0,space=0,digit=0,other=0;
 while(count++<=9)
 {
  c=getchar();
  if( ' '== c|| '\n' == c)
  {
   space++;
  }
  else
  if(c>='a'&&c<='z'||c>='A'&&c<='Z')
  letter++;
  else
  if(c>='0'&&c<='9')
  digit++;
  else
  other++;
 }
 printf("letter = %d, blank = %d, digit = %d, other = %d\n",letter,space,digit,other);
 return 0;
 }
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM