#include <stdio.h> int main(){ char c; //用戶輸入的字符 int shu=0;//字符總數 int letters=0, // 字母數目 space=0, // 空格數目 digit=0, // 整數數目 others=0; // 其他字符數目 printf("輸入一些字符:"); 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++; shu++; } printf("\n統計結果:\n字符總數=%d\n英文字母=%d\n空格=%d\n整數=%d\n其他字符=%d\n\n", shu,letters, space, digit, others); return 0; }