满意答案
1能够进行任意多个数的加减乘除四则运算,比如想要计算1+2+3,输入1+2+3=,得到结果612345678910111213141516171819202122232425262728293031323334353637383940414243444546474849#include int jia(int a,int b){ int s; s=a+b; return s;}int jian(int a,int b){ int s; s=a-b; return s;}int cheng(int a,int b){ int s; s=a*b; return s;}int chu(int a,int b){ int s; s=a/b; return s;} void main(){ int a,b,x,y,i; char c; printf("请输入运算式:\n"); scanf("%d%c%d",&a,&c,&b); x=a; y=b; for(i=0;;i++) { if(c=='+')x=jia(x,y); else if(c=='-')x=jian(x,y); else if(c=='*')x=cheng(x,y); else if(c=='/')x=chu(x,y); c=getchar(); if(c=='=') { printf("%d\n",x); break; } scanf("%d",&y); }}
02分享举报