题目:输入一个算式,输出答案;
要求利用函数调用,
±*/%五种运算
int calculate(int a,char sign,int b)
{
switch(sign)
{
case'+':return a+b;
case'-':return a-b;
case'*':return a*b;
case'/':return a/b;
case'%':return a%b;
defalut:break;
}
}
int main()
{
int x,y;
char z;
cin>>x>>z>>y;
cout<<calculate(x,z,y)<<end1;
return 0;
}
这里主要运用switch…case 语句。进行判断;