c语言 用switch语句写个加、减、乘、除法的计算器程序

用switch语句写个加、减、乘、除法的计算器程序

第1个回答  推荐于2017-10-13
#include <stdio.h>
int main()
{
double m,n,result;
char a;
printf("Please input two number as a,b:");
scanf("%lf%c%lf",&m,&a,&n);
switch(a)
{
case '+':
printf("%lf%c%lf=%lf",m,a,n,m+n);
break;
case '-':
printf("%lf%c%lf=%lf",m,a,n,m-n);
break;
case '*':
printf("%lf%c%lf=%lf",m,a,n,m*n);
break;
case '/':
printf("%lf%c%lf=%lf",m,a,n,m/n);
break;
}
getchar();
return 0;
}本回答被提问者采纳
第2个回答  2013-04-08
#include <stdio.h>
int main( )
{
float a, b;
char op;
scanf("%c%f%f", &op, &a, &b);
switch (op)
{
case '+': printf("%.2f+%.2f=%.2f\n", a, b, a + b); break;

case '-': printf("%.2f-%.2f=%.2f\n", a, b, a - b); break;

case '*': printf("%.2f*%.2f=%.2f\n", a, b, a * b); break;

case '/': if (b != 0) printf("%.2f/%.2f=%.2f\n", a, b, a / b);
else printf("除数为零无意义\n");
break;
default : printf("未知运算符\n");
}
return 0;
}
第3个回答  2009-11-08
#include<iostream.h>
int main()
{
double m,n,sum,cha,ji,shang;
char a;
cout<<"输入两个数"<<endl;
cin>>m>>n;
sum=m+n;
cha=m-n;
ji=m*n;
shang=m/n;
cout<<"输入算法"<<endl;
cin>>a;
switch(a)
{
case '+':cout<<m<<'+'<<n<<'='<<sum<<endl;
break;
case '-':cout<<m<<'-'<<n<<'='<<cha<<endl;
break;
case '*':cout<<m<<'*'<<n<<'='<<ji<<endl;
break;
case '/':cout<<m<<'/'<<n<<'='<<shang<<endl;
break;
}
system("PAUSE");
return 0;
} C++写的 只要把输入输出方式改下就可以了。思路应该一样的
第4个回答  2009-11-08
我这有个用C++ MFC编的计算器 要不要

c语言 用switch语句写个加、减、乘、除法的计算器程序
int main(){ double m,n,result;char a;printf("Please input two number as a,b:");scanf("%lf%c%lf",&m,&a,&n);switch(a){ case '+':printf("%lf%c%lf=%lf",m,a,n,m+n);break;case '-':printf("%lf%c%lf=%lf",m,a,n,m-n);break;case '*':printf("%lf%c...

用C语言做一个计算器,能实现加减乘除混合运算?
int main() { char operator;double num1, num2, result;printf("Enter an operator (+, -, *, \/): ");scanf("%c", &operator);printf("Enter two numbers: ");scanf("%lf %lf", &num1, &num2);switch (operator) { case '+':result = num1 + num2;break;case '-':resul...

用c语言设计一个简单的加减乘除计算器
1、打开visual C++ 6.0-文件-新建-文件-C++ Source File。2、输入预处理命令和主函数:#include \/*函数头:输入输出头文件*\/,void main()\/*空类型:主函数*\/。3、定义变量:int a,b,d; \/*定义变量的数据类型为整型*\/,char c;\/*定义变量的数据类型为字符型*\/。4、输入四则运算式:pri...

...的程序(c=a运算符b),只做加、减、乘、除四种运算。(用switch...
&a,&b,&c); \/\/输入需要分开,如:1 + 2 switch(b) { case '+': result=a+c; break; case '-': result=a-c; break; case '*': result=a*c; break; case '\/

用C语言编一个+,-,*,\/的计算器怎样写
最简单的.include <stdio.h> main(){ int a,b,c;char ch;while(1){ scanf("%d%c%d",&a,&ch,&b);if((a==0)||(b==0))break;switch(ch){ case '+':c=a+b;break;case '-':c=a-b;break;case '*':c=a*b;break;case '\/':c=a\/b;break;default:} printf("%d%c%d=...

...的程序(c=a运算符b),只做加、减、乘、除四种运算。(用switch...
include <functional> include include <string> using namespace std;int add(int i, int j){ return i + j;} \/\/ 使用函数调用运算符 struct divide { int operator()(int i, int j){ return i \/ j;} };auto mod = [](int i, int j) {return i % j; };map<string, functi...

C语言作业,编写一个简单的计算器,实现加减乘除运算,谢谢大家
return 0;}int switchs(double a,double b,char s){ switch (s){case '+':{cls();printf("a+b\\n"); Sleep(500);printf("=%0.3lf+%0.3lf\\n",a,b);Sleep(500);printf("=%0.3lf\\n\\007",a+b);Sleep(500);}break;case '...

c语言计算器加减乘除
include <stdio.h>int main() { double a, b, d = 0.0; char c; while (1) { printf("输入一个算式,如:1+2:"); scanf("%lf%c%lf", &a, &c, &b); int f = 1; switch (c) { case '-': d = a - b; break; case '+': ...

c# windows窗体应用程序中怎么用switch写一个计算器的程序
\/*设计一个简单的四则计算器*\/ string[] 名称 = { "+", "-", "*", "\/" }; Button[] 控件组 = Array.ConvertAll(名称, 控件 => new Button()); EventHandler[] 按钮事件 = new EventHandler[] { 按钮加_Click, 按钮减_Click, 按钮乘_Click, 按钮除_Click }; fore...

用c语言写一个只有加减乘除的计算器,它可以多次输入,直到用户想结束再退...
switch (ch){ case '+':{ printf ("%lf %c %lf = %lf\\n", a, ch, b, a + b);break;} case '-':{ printf ("%lf %c %lf = %lf\\n", a, ch, b, a - b);break;} case '\/':{ printf ("%lf %c %lf = %lf\\n", a, ch, b, a \/ b);break;} case '*'...

相似回答