#include<stdio.h>
#include<stdlib.h>
#include<string.h>
float cal(int a,char sys,int b);
void main()
{
int a=0,b=0;
char sys='\0';
float c=0.0;
printf("请输入第一个数,符号,第二个数:");
scanf_s("%d%c%d",&a,&sys,&b);
c=cal(a,sys,b);
printf("%d%c%d=%f",a,sys,b,c);
system("pause");
}
float cal(int a,char sys,int b)
{
float c=0.0;
switch(sys)
{
case'+':c=(float)a+b; return c; break;
case'-':c=(float)a-b; return c;
case'*':c=(float)a*b; return c;
case'/':if(b!=0)
{c=(float)a/b;return c;}
else {printf("Devided by 0."); exit(0);} //终止函数
}
}
02-20
1860
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-06
2693
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)