简单计算器(20)

来源:互联网 发布:网游等级算法 编辑:程序博客网 时间:2024/05/19 22:25
#include<stdio.h>int main(){int a,b;int flag;char ch;//while(scanf("%d",&a)!=EOF)//{scanf("%d",&a);scanf("%c",&ch);flag=0;while(ch!='='){scanf("%d",&b);switch(ch){case '+':a+=b;break;case '-':a-=b;break;case '*':a*=b;break;case '/':if(b==0)flag=1;else a/=b;break;default :flag=1;break;}if(flag==1) break;scanf("%c",&ch);}if(flag==1) printf("ERROR\n");else printf("%d\n",a);//}}

这道题目如果不要注释就是正确的,但是不可以重复测试。要注释里的内容可以重复测试,但是会有小bug!

对C语言的语言还是存在不少误区!!!

0 0
原创粉丝点击