作者在 2012-10-29 15:08:34 发布以下内容
//:输入一个字符串,统计大写字母,小写字母,空格,数字以及其他个数
#include <stdio.h>
const int N = 100;
int main(){
char *p, string[N];
int uplet, lowlet, space, digit, other;
uplet = lowlet = space = digit = other = 0;
printf("输入字符串:");
gets(string);
p = string;
while(*p!=''){
if(*p>='A' && *p<='Z'){
uplet++;
}else if(*p>='a' && *p<='z'){
lowlet++;
}else if(' '==*p){
space++;
}else if(*p>='0' && *p<='9'){
digit++;
}else{
other++;
}
p++;
}//while
printf("uplet = %d, lowlet = %d, space = %d, digit = %d, other = %dn", uplet, lowlet, space, digit, other);
return 0;
}
#include <stdio.h>
const int N = 100;
int main(){
char *p, string[N];
int uplet, lowlet, space, digit, other;
uplet = lowlet = space = digit = other = 0;
printf("输入字符串:");
gets(string);
p = string;
while(*p!=''){
if(*p>='A' && *p<='Z'){
uplet++;
}else if(*p>='a' && *p<='z'){
lowlet++;
}else if(' '==*p){
space++;
}else if(*p>='0' && *p<='9'){
digit++;
}else{
other++;
}
p++;
}//while
printf("uplet = %d, lowlet = %d, space = %d, digit = %d, other = %dn", uplet, lowlet, space, digit, other);
return 0;
}