#include int main() { char str[100],i; int upper = 0, lower = 0, number = 0, special = 0,whitesp=0; printf("enter string"); gets(str); for (i = 0; i < str[i]!='\0'; i++) { if (str[i] >= 'A' && str[i] <= 'Z') upper++; else if (str[i] >= 'a' && str[i] <= 'z') lower++; else if (str[i]>= '0' && str[i]<= '9') number++; else if(str[i]==' ') whitesp++; else special++; } printf("Upper case letters: %d</p><p>",upper); printf("lower case letters: %d</p><p>",lower); printf("Numbers: %d</p><p>",number); printf("whitespace: %d</p><p>",whitesp); printf("sp chararcter: %d</p><p>",special); return 0; }
以上是使用C語言計算一個句子中的空格、大寫字母和小寫字母的數量的詳細內容。更多資訊請關注PHP中文網其他相關文章!