题目:简易计算器
自定义一个函数,实现整数的加、减、乘、除、模运算,输入不需要空格分隔。
例如,输入:
3/2
输出:
1
第二次学函数,可能写的有些麻烦,不喜勿喷Thanks♪(・ω・)ノ
#include <cstdio>
int jisuanqi(int x,char ch,int y){
if(ch=='+') return x+y;
else if(ch=='-') return x-y;
else if(ch=='*') return x*y;
else if(ch=='/') return x/y;
else if(ch=='%') return x%y;
}
int main(){
int a,b;
char c;
scanf("%d%c%d",&a,&c,&b);
int d = jisuanqi(a,c,b);
printf("%d",d);
return 0;
}