| 
 | 
 
1鱼币 
#include<stdio.h> 
void main() 
{ 
 char a; 
 int b=0,c=0,d=0,e=0; 
 printf("请输入一行字符:\n"); 
 a=getchar(); 
 while(a!='\n') 
 { 
  if((a>='a'&&c<='z')||(a>='A')&&c<='Z') 
   b++; 
  else if(c==' ') 
   c++; 
  else if(c<='9'&&c>='0') 
   d++; 
  else 
   e++; 
 } 
 printf("字母个数为:%d\n空格个数为:%d\n数字个数为;%d\n其它字符的个数为:\n",b,c,d,e); 
} 
 
 
 
#include<stdio.h> 
void main() 
{ 
 char a; 
 int b=0,c=0,d=0,e=0; 
 printf("请输入一行字符:\n"); 
 while(( a=getchar())!='\n') 
 { 
  if((a>='a'&&c<='z')||(a>='A')&&c<='Z') 
   b++; 
  else if(c==' ') 
   c++; 
  else if(c<='9'&&c>='0') 
   d++; 
  else 
   e++; 
 } 
 printf("字母个数为:%d\n空格个数为:%d\n数字个数为;%d\n其它字符的个数为:\n",b,c,d,e); 
} 
这两个程序差别在那啊? 
 |   
 
 
最佳答案
查看完整内容 
第一个代码是 错误的。因为他只能输入一个有效字符。第二个因为用了循环(while) 所以可以正常工作。【欢迎加入鱼c-Linux 官方讨论群 20602-7176】 
 
 
 
 
 
 
 |