本帖最后由 青青河边草Rt 于 2015-6-18 21:12 编辑
- #include<stdio.h>
- int main(){
- int a,b;
- float result;
- char ch;
- printf("请输入一个算式:");
- scanf("%d%c%d",&a,&ch,&b);
- switch(ch){
- case '+':
- result = a+b;
- printf("%f",result);
- break;
- case '-':
- result = a-b;
- printf("%f",result);
- break;
- case '*':
- result = a*b;
- printf("%f",result);
- break;
- case '/':
- result = a/(float) b;
- printf("%.2f",result);
- break;
- case '%':
- result = a%b;
- printf("%f",result);
- break;
- default:
- printf("该计算器功能有限,实现不了太难的功能,有待待完善!\n");
- break;
-
- }
-
- }
复制代码
|