www.3112.net > 用switCh语句编写一个计算器

用switCh语句编写一个计算器

#include int main( ) { double a, b; char op; scanf("%lf%c%lf", &a, &op, &b); switch (op) { case '+': printf("%lf + %lf = %lf\n", a, b, a + b); break; case '-': printf("%lf - %lf = %lf\n", a, b, a - b); break; case '*': printf("...

else后面可以用printf("error"),用z=0不太好,会有误导

#include "stdio.h" #include "math.h" void main() {float data1,data2; char a; printf("input:"); scanf("%f,%f,%c",&data1,&data2,&a); switch (a) {case '+':printf("%f%c%f=%f\n",data1,a,data2,data1+data2);break; case '-':printf("%f%...

#include #includeint main(){char input[40];char temp1[20];char temp2[20];char op;int flag=0,flag2=0;bool tempbool=0,tempbool2=0;while (!tempbool){flag=0,flag2=0;tempbool=0,tempbool2=0;gets(input);//整行读取for (int i=0;i

//满足要求;如果觉得不好看,想单独做主菜单,你自己可以稍微改改#include #include int main() { int a,b,sum; char c; while (true) { printf("输入格式:数字 运算符 数字: 1+2\n"); scanf("%d%c%d",&a,&c,&b); switch(c) { case '+': sum=a+b; ...

代码如下:#include void main() { int a,b,sum,flag=0; char fh; //用来记录用户输入的运算符 scanf("%d %c %d =",&a,&fh,&b); //按照这个格式输入运算符例如输入 “1 + 1 =”然后按回车 switch(fh) { case '+':sum=a+b;break; case '-':sum=a-b;...

#includevoid main() { float a,b,c; char d; scanf("%f%c%f",&a,&d,&b); switch ( d ) { case '+': c=a+b; break; case '-': c=a-b; break; case '*': c=a*b; break; case '/': c=( b!=0 )?(a/b):(0); break; default: c=0; break; } printf("%...

如果我的回答你还满意记得选个满意答案哦#include void main() { float a,b; char c; printf("请输入两个操作数:"); scanf("%f",&a); scanf("%f",&b); getchar(); printf("请选择操作运算:"); scanf("%c",&c); switch(c) { case '+': printf("结...

#include #include int main() { int numOne = 0; int numTwo = 0; int result = 0; char operator; cin >> a; cin >> b; cin >> operator; switch (operator) { case "+": sum = numOne + numTwo; break; case "-": sum = numOne - numTwo; bre...

其实还可以加个循环输入的,不过怕你输入格式错误,没加了。。。#include #include int main() { double a,b; char c; scanf("%lf%c%lf",&a,&c,&b); switch(c) { case'+':printf("=%g",a+b);break; case'-':printf("=%g",a-b);break; case'*':pr...

网站地图

All rights reserved Powered by www.3112.net

copyright ©right 2010-2021。
www.3112.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com