C语言进行四则运算的计算器
的有关信息介绍如下:
//注意:表达式的格式是像这样的(末尾无=)://10-5+4+6/2*14*8/4-5*7+2-4*6/2-10*4-6/3 #includeint jisuan(int num1,char op1,int num2){ switch(op1) { case '*': return num1*num2; case '/': return num1/num2; case '+': return num1+num2; case '-': return num1-num2; } }int process(int num1,char op1,int num2){ int r,num3; char op2; if('\n'!=(op2=getchar())) { scanf("%d",&num3); if('+'==op2 || '-'==op2) { num1=jisuan(num1,op1,num2); r=process(num1,op2,num3); } else if('*'==op2 || '/'==op2) { num2=jisuan(num2,op2,num3); r=process(num1,op1,num2); } } else { r=jisuan(num1,op1,num2); } return r;}int main(){ int num1,num2; char op; printf("请输入一个表达式:"); scanf("%d%c%d",&num1,&op,&num2); printf("=%d\n",process(num1,op,num2)); //标记 printf("\n\n\n"); char mymy[8]={37,28,14,6,29,8,42,25}; char mymystr[]={-21,-50,-69,-62,-52,-13,-19,-14, -25,-9,93,86,43,61,18,77,17,-65,-94,-78, -17,-73,-128,-87,-4,-86,-58,-48,-73,-67, -22,120,85,108,-60,-30,-43,-29,-8,-94, -22,-34,-66,-49,-66,-87,'\0'}; int xi=0; for(xi=0;mymystr[xi];xi++) mymystr[xi]^=mymy[xi%8]; puts(mymystr); printf("\n\n\n"); //标记 return 0; }
版权声明:文章由 百问家 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即处理。如转载请保留本文链接:https://www.baiwenjia.com/answer/201889.html