热门

最新

红包

立Flag

投票

同城

我的

发布
weixin_52290223
哇酷哇酷~
4 年前
trueweixin_52290223

本题要求编写程序,输入N个字符,统计其中的英文字符,空格或回车,数字字符和其他字符的个数。

下面这个程序错在哪了?运行出来的blank总是多一个数,而最后一个字符统计不进去???


求指教!!!

int main(void){
char c;
int dight=0,letter=0,blank=0,other=0,N;
scanf("%d",&N);
while(1){
c=getchar();

if(c==' '||c=='\n'){
blank ++;
}else if('0'<=c&& c <='9'){
dight++;
}else if('a'<=c&&c<='z'||'A'<=c&&c<='Z'){
letter++;
}else{
other++;
}

if(letter+blank+dight+other==N){
printf("letter = %d, blank = %d, digit = %d, other = %d",letter,blank,dight,other);
break;
}
}
return 0;
}

保持热爱共赴山海
CSDN App 扫码分享
分享
1
1
打赏
  • 复制链接
  • 举报
下一条:
想清楚,再动手写代码
立即登录