c语言题 判别字符个数 急!!!!1

来源:百度知道 编辑:UC知道 时间:2024/09/21 22:41:33
从键盘输入10行表达式,要求输出运算符号(+ - * / )有几个,数字有

几个,其他字符有几个 ?

例如 (3+63)*9+9/4=9 则运算符号有4个,数字有7个,其他字符有3个

但要一次性输入10行,统计10行总的运算符号,数字,其他字符有多少

个。

#include <stdio.h>

#define N 10

int main()
{

int i,oper=0,digit=0,other=0;
char ch;

for(i=0;i<N;i++)
{
while((ch=getchar())!='\n')
{
if(ch=='+'||ch=='-'||ch=='*'||ch=='/')
{
oper++;
}
else if(ch<='9'&&ch>='0')
{
digit++;
}
else
{
other++;
}
}
}
printf("运算符号有%d个,数字有%d个,其他字符有%d个!\n",oper,digit,other);
return 0;
}