编程题 统计一字串中字母,数字和其他字符的个数,谢谢各位 速度啊~~~

来源:百度知道 编辑:UC知道 时间:2024/06/27 22:43:46

#include "stdio.h"
void main()
{
char str[255],*p=str;
int zimu,shuzi,other;
zimu=shuzi=other=0;
gets(str);
while(*p)
{
if(*p>='0'&&*p<='9')
shuzi++;
else if(*p>='A' && *p<='Z' || *p>='a' && *p<='z')
zimu++;
else other++;
p++;
}
printf("zimu:%d,shuzi:%d,other:%d",zimu,shuzi,other);
}

#include <stdio.h>
main(){
char s[255],l=0,n=0,o=0,i=0;
printf("Enter a string\n");
gets(s);
while(s[i]){
if (s[i]>='a' && s[i]<='z' || s[i]>='A' && s[i]<='Z') l++;
else if (s[i]>='0' && s[i]<='9') n++;
else o++;
i++;
}
printf("%d letters, %d number, %d other\n",l,n,o);
}

#include <stdio.h>
int main()
{
char a[100],*p;