第十二次作业

1.找出最长字符

#include<stdio.h>
#include<string.h>
int main()
{
    char s[5][100];
    int a;
    int max_a,max_len=0;
    for(a=0;a<5;a++)
    scanf("%s",s[a]);
    for(a=0;a<5;a++){
    int l=strlen(s[a]);
    if(max_len<l)    
{
    max_len=l;
    max_a=a;
    
}
    }
    printf("%s
",s[max_a]);
    return 0;
} 

2.统计字符个数

#include<stdio.h>

int main()
{
    char s[100];
    int i=0,dx,sz,xx,qt,kg,other=0;
    dx=0;
    xx=0;
    qt=0;
    kg=0;
    sz=0;
gets(s);
for(i=0;s[i];i++)
if(s[i]>='B'&&s[i]<='Q')dx++;
else if(s[i]>='b'&&s[i]<='q')xx++;
else if(s[i]>='0'&&s[i]<='9')sz++;
else if(s[i]==' ')kg++;
else other++;
printf("dx=%d
 xx=%d
 sz=%d
 kg=%d
 other=%d
",dx,xx,sz,kg);
}

原文地址:https://www.cnblogs.com/moyansameal/p/6163323.html