例3-7 统计字符

例3-7 统计字符

程序核心——循环语句判断语句的镶嵌

程序

#四则运算
程序核心——判断语句
##程序

include<stdio.h>

int main()
{
int digit,letter,other,i;//定义三个变量统计结果
char ch;

digit=letter=other=0;

printf("Enter 10 characters:");
for(i=1;i<=10;i++)
{
    ch=getchar();
    if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='z'))
        letter++;
    else if(ch<='9'&&ch>='0')
        digit++;
    else
        other++; 
 } 
printf("letter=%d,digit=%d,other=%d\n",letter,digit,other);

return 0;

}##结果
Enter 10 characters:lkj098、、、、
letter=3,digit=3,other=4


Process exited after 16.71 seconds with return value 0
请按任意键继续. . .
.
```

分析

重点:ch=getchar();向ch输入一个字符

猜你喜欢

转载自www.cnblogs.com/5236288kai/p/10582582.html