1.用switch结构编写一个处理四则运算的程序。#includestdiohint main float v1 v2;char op;printfplease type your expressionIn;scanffCf&v1&op &v2;switchcase+printf10f+101=10fnv1v2v1+v2;break; case _printf10f-10f=10fnv1v2v1-
代码存在语法错误,以下为修改后的代码:
#include<stdio.h>
int main() { float v1, v2; char op; printf("please type your expression: "); scanf("%f %c %f",&v1,&op, &v2); switch(op) { case '+': printf("%1.0f+%1.0f=%1.0f\n",v1,v2,v1+v2); break; case '-': printf("%1.0f-%1.0f=%1.0f\n",v1,v2,v1-v2); break; case '': printf("%1.0f%1.0f=%1.0f\n",v1,v2,v1*v2); break; case '/': if(v2==0) { printf("除数为零\n"); break; } else { printf("%1.0f/%1.0f=%1.2f\n",v1,v2,v1/v2); break; } default: printf("运算符错误\n"); } return 0; }
原文地址: https://www.cveoy.top/t/topic/Nd9 著作权归作者所有。请勿转载和采集!