10.8輸入一行文字,找出其中大寫字母、小寫字母、空格、數字及其他字符各有多少?


10.8輸入一行文字,找出其中大寫字母、小寫字母、空格、數字及其他字符各有多少?

#include <stdio.h>

int main(){
    char * p,str[50];
    int upper=0, lower=0,digit=0,space=0,other=0;
    p=str;
    printf("請輸入一行字符,以回車鍵結束.\n");
    gets(str);
    while((*p) != '\0'){
        if(*p>='A' && *p<='Z') ++upper;
        else if(*p>='a' && *p<='z') ++lower;
        else if(*p>='0' && *p<='9') ++digit;
        else if(*p==' ') ++space;
                else ++other;
        p++;
    }
    printf("the number of upper is %d\n",upper);
    printf("the number of lower is %d\n",lower);
    printf("the number of digit is %d\n",digit);
    printf("the number of space is %d\n",space);
    printf("the number of other is %d\n",other);
    return 0;
}

 

結果:


免責聲明!

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



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