本題要求編寫程序,輸入一行字符,統計其中數字字符、空格和其他字符的個數。建議使用switch語句編寫。
輸入格式:輸入在一行中給出若干字符,最后一個回車表示輸入結束,不算在內。
輸出格式:在一行內按照 blank = 空格個數, digit = 數字字符個數, other = 其他字符個數 的格式輸出。請注意,等號的左右各有一個空格,逗號后有一個空格。
輸入樣例:在這里給出一組輸入。例如:
Reold 12 or 45T 輸出樣例:在這里給出相應的輸出。例如:
blank = 3, digit = 4, other = 8
直接放代碼:
#include <stdio.h> int main() { char c; int letters=0,space=0,digit=0,other=0; while ((c=getchar())!='\n') { if (c >= 'a'&&c <= 'z' || c >= 'A'&&c <= 'Z') { other++; } else if (c == ' ') { space++; } else if (c >= '0'&&c <= '9') { digit++; } else { other++; } } printf("blank = %d, digit = %d, other = %d",space,digit,other); return 0; }
贈人玫瑰手有余香~
NO THANKS!不用謝~
喜歡記得關注,評論~感謝各位大佬