6-7 简单计算器

来源:互联网 发布:丑老太婆网络照片 编辑:程序博客网 时间:2024/06/07 06:26
//简单计算器#include<stdio.h>int main(int argc,char const *argv[]){int value1,value2;int sum=0;int flag=1;char ch;scanf("%d",&value1);while((ch=getchar())!='='){scanf("%d",&value2);if(ch=='+')sum=value1+value2;else if(ch=='-')sum=value1-value2;else if(ch=='*')sum=value1*value2;else if(ch=='/'){if(value2==0){flag=0;break;}elsesum=value1/value2;}else{flag=0;break;}value1=sum;}if(flag==0)printf("error\n");elseprintf("%d\n",sum);return 0;} 

原创粉丝点击