A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 又欠又欠 中级黑马   /  2016-4-6 21:19  /  617 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

2.输入一行字符,分别统计出其中字母、空格、数字和其他字符的个数。 #include<stdio.h> 
int letter,digit,space,others; void main() { 
 void count(char[]);  char text[80]; 
 printf("Please input string:\n");  gets(text); 
 printf("string:\n");  puts(text);  letter=0;  digit=0;  space=0;  others=0;  count(text); 
 printf("letter:%d,digit:%d,space:%d,others:%d\n",letter,digit,space,others); } 
void count(char str[]) { 
 int i; 
 for(i=0;str[i]!='\0';i++) 
  if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z'))    letter++; 
  else if(str[i]>='0'&&str[i]<='9')    digit++; 
  else if(str[i]==32)    space++;   else 
   others++; }

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马