作業3(3)輸入 15 個字符,統計其中英文字母、空格或回車、數字字符和其他字符的個數


#include<stdio.h>
int main(void)
{
    int yinwen,shuzi,koge,other;
    char ch;
    int i;
    yinwen=shuzi=koge=other=0;
    printf("Enter 15 characters:");
    for(i=1;i<=15;i++){
        ch=getchar( );
            if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
                yinwen++;
            else if(ch>='0'&&ch<='9')
                shuzi++;
            else if(ch>=' '&&ch<='\n')
                koge++;
            else
                other++;
    }
    printf("yinwen=%d,shuzi=%d,koge=%d,other=%d\n",yinwen,shuzi,koge,other);

    return 0;

}

 


免責聲明!

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



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