下面要写的几个代码都是与字符和字符串有关的。第一个:统计各个字符串的个数

作者在 2011-05-15 22:58:39 发布以下内容
#include<stdio.h>
main()
{
     int letters=0,numbers=0,space=0,others=0;  /*先把字母,数字,空格,其他设为零*/
     char ch;
     printf("please input some characters\n");
     while((ch=getchar())!='\n')
     {
         if(ch>='a'&&ch<='z'||ch>='A'&&ch<='Z')
               letters++;
         else if(ch>='0'&&ch<='9')
               numbers++;
         else if(ch==' ')
               space++;
         else
              others++;
      }
      printf("char=%d  number=%d  space=%d  others=%d\n",letters,numbers,space,others);
}
 
 
 
 
应该看得懂吧,不加注释了,本来准备再写几个代码的,没想到打字太慢,时间太晚,明天再写吧,玩一盘dota
 
     
 
 
c语言代码 | 阅读 802 次
文章评论,共0条
游客请输入验证码
文章归档