C语言 任意输入一串字符,统计其中大写字母 小写字母 数字和其他字符的分别数量

#include <stdio.h>
#include <string.h> 
main()
{
    char zf[100];
    int upper=0,lower=0,number=0,other=0,a;
    gets(zf);
    for(a=0;a<strlen(zf);a++)
    {
        if(zf[a]>='A' && zf[a]<='Z') upper++;
        else if(zf[a]>='a' && zf[a]<='z') lower++;
        else if(zf[a]>='0' && zf[a]<='9') number++;
        else other++;
    }
    printf("大写字母为%d,小写字母为%d,数字为%d,其他%d",upper,lower,number,other);


 getch();
 }
#include <stdio.h>
#include <string.h> 
main()
{
    char zf[100];
    int upper=0,lower=0,number=0,other=0,a;
    gets(zf);
    for(a=0;zf[a]!='\0';a++)
    {
        if(zf[a]>='A' && zf[a]<='Z') upper++;
        else if(zf[a]>='a' && zf[a]<='z') lower++;
        else if(zf[a]>='0' && zf[a]<='9') number++;
        else other++;
    }
    printf("大写字母为%d,小写字母为%d,数字为%d,其他%d",upper,lower,number,other);


 getch();
 }
#include <stdio.h>
main()
{
    char zf;
    int upper=0,lower=0,number=0,other=0;
    for(;(zf=getchar())!='\n';)
    {
        if(zf>='A' && zf<='Z') upper++;
        else if(zf>='a' && zf<='z') lower++;
        else if(zf>='0' && zf<='9') number++;
        else other++;
    }
    printf("大写字母为%d,小写字母为%d,数字为%d,其他%d",upper,lower,number,other);


 getch();
 }
#include <stdio.h>
main()
{
    char zf;
    int upper=0,lower=0,number=0,other=0;
    while((zf=getchar())!='\n')
    {
        if(zf>='A' && zf<='Z') upper++;
        else if(zf>='a' && zf<='z') lower++;
        else if(zf>='0' && zf<='9') number++;
        else other++;
    }
    printf("大写字母为%d,小写字母为%d,数字为%d,其他%d",upper,lower,number,other);


 getch();
 }
#include <stdio.h>
main()
{
    char zf;
    int upper=0,lower=0,number=0,other=0;
    scanf("%c",&zf);
    while(zf!='\n')
    {
        if(zf>='A' && zf<='Z') upper++;
        else if(zf>='a' && zf<='z') lower++;
        else if(zf>='0' && zf<='9') number++;
        else other++;
        scanf("%c",&zf);
    }
    printf("大写字母为%d,小写字母为%d,数字为%d,其他%d",upper,lower,number,other);


 getch();
 }
#include <stdio.h>
#include <string.h> 
main()
{
    char zf[100];
    int upper=0,lower=0,number=0,other=0,a;
    scanf("%s",zf);
    for(a=0;a<strlen(zf);a++)
    {
        if(zf[a]>='A' && zf[a]<='Z') upper++;
        else if(zf[a]>='a' && zf[a]<='z') lower++;
        else if(zf[a]>='0' && zf[a]<='9') number++;
        else other++;
    }
    printf("大写字母为%d,小写字母为%d,数字为%d,其他%d",upper,lower,number,other);


 getch();
 }
#include <stdio.h>
#include <string.h> 
main()
{
    char zf[100];
    int upper=0,lower=0,number=0,other=0,a;
    gets(zf);
    for(a=0;a<100;a++)
    {        
                if(zf[a]=='\0')break;
        if(zf[a]>='A' && zf[a]<='Z') upper++;
        else if(zf[a]>='a' && zf[a]<='z') lower++;
        else if(zf[a]>='0' && zf[a]<='9') number++;
        else other++;
    }
    printf("大写字母为%d,小写字母为%d,数字为%d,其他%d",upper,lower,number,other);


 getch();
 }
    

 

posted @ 2025-09-02 17:07  myrj  阅读(9)  评论(0)    收藏  举报