代码改变世界

作业三-3

2013-10-18 17:53  Summer.xia  阅读(165)  评论(0编辑  收藏  举报
/*输入 15 个字符,统计其中英文字母、空格或回车、数字字符和其他字符的个数*/
#include<stdio.h> int main(void) { int digit,letter,blank,other; /*digit,letter,blank,other分别代表英文字母,空格或回车,数字字符和其他字符的个数*/
char ch; /*定义一个字符变量ch*/
int i; /*赋初值为0*/
digit
=letter=other=blank=0; printf("Enter 15 characters:"); /*用for函数分别计算累加 */
for(i=1;i<=15;i++){ ch=getchar(); if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')) letter++; else if(ch>='0'&&ch<='9') digit++; else if(ch>=' '||ch<='\r')
/*"\r"代表回车*/ blank
++; else other++; } printf("letter=%d,digit=%d,blank=%d\n,other=%d\n",letter,digit,blank,other); return 0; }