C语言课后习题(46)
谭浩强C语言第五版的一些课后习题第七章 第九题统计字符串中的字母,数字,空格和其他(应用gets而不是scanf)int zm=0,num=0,space=0,other=0;int main(){void count(char s[]);char str[40];printf("输入字符串:\n");gets(str);count(str);printf("字母个数为:%d 数字个数为:%d 空
·
谭浩强C语言第五版的一些课后习题
第七章 第九题
统计字符串中的字母,数字,空格和其他(应用gets而不是scanf)
int zm=0,num=0,space=0,other=0;
int main(){
void count(char s[]);
char str[40];
printf("输入字符串:\n");
gets(str);
count(str);
printf("字母个数为:%d 数字个数为:%d 空格个数为:%d 其他个数为:%d\n",zm,num,space,other);
}
void count(char s[]){
int i=0;
while(s[i]!='\0'){
if((s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z')){
zm++;
}
else if(s[i]>='0'&&s[i]<='9'){
num++;
}
else if(s[i]==' '){
space++;
}else{
other++;
}
i++;
}
}
更多推荐



所有评论(0)