编程题:输入一行文字,分别统计出其中英文大写字母、小写字母、空格、数字和其它字符的个数。(用指针和

(用指针和数组实现)

第1个回答  2011-04-27
#include <stdio.h>
#include <string.h>
void fun(char *p);
int main(){
char values[100];
int i;
gets(values);
fun(values);
return 0;
}
void fun(char *p){
int i;
int daxie=0;
int xiaoxie=0;
int kongge=0;
int shuzi=0;
int other=0;
//英文大写字母、小写字母、空格、数字和其它字符
for(i=0;i<strlen(p);i++){
if(p[i]>='A'&&p[i]<='Z')
daxie++;
else if(p[i]>='a'&&p[i]<='z')
xiaoxie++;
else if(p[i]==' ')
kongge++;
else if(p[i]>='0'&&p[i]<='9')
shuzi++;
else other++;
}
printf("大写字母:%d\n小写字母:%d\n空格:%d\n数字:%d\n其他字符:%d\n",daxie,xiaoxie,kongge,shuzi,other);

}
第2个回答  2011-05-04
#include<stdio.h>
main(){
int i=0;
int m=0;
int n=0;
char c;
clrscr();
while((c=getchar())!='\n'){
if (65<=c&&c<=90) i++;
else if(97<=c&&c<=122) m++;
else if(48<=c&&c<=57) n++;

}
printf("da xie zi mu you %d ge,xiao xie zi mu you %d ge,shu zi you %d ge!",i,m,n);

}

程序测试成功!
另外,站长团上有产品团购,便宜有保证本回答被网友采纳
相似回答