3个回答
展开全部
#include<stdio.h>
void main()
{ int a,b;
char ch;
printf("请输入两个整数和一个四则运算符:");
scanf("%d %d %ch",&a,&b,&ch);
switch(ch)
{
case '+':printf("%d+%d=%d\n",a,b,a+b);break;
case '-':printf("%d-%d=%d\n",a,b,a-b);break;
case '*':printf("%d*%d=%d\n",a,b,a*b);break;
case '/':printf("%d/%d=%lf\n",a,b,(double)(a)/b);break;
}
}
void main()
{ int a,b;
char ch;
printf("请输入两个整数和一个四则运算符:");
scanf("%d %d %ch",&a,&b,&ch);
switch(ch)
{
case '+':printf("%d+%d=%d\n",a,b,a+b);break;
case '-':printf("%d-%d=%d\n",a,b,a-b);break;
case '*':printf("%d*%d=%d\n",a,b,a*b);break;
case '/':printf("%d/%d=%lf\n",a,b,(double)(a)/b);break;
}
}
展开全部
int a,b,sum;
char m;
cout<<"输入一个整数"<<endl;
cin>>a;
cout<<"输入四则运算(+,-,*,/)"<<endl;
cin>>m;
cout<<"输入第二个整数"<<endl;
cin>>b;
switch(m)
{
case '+':sum=a+b;break;
case '-':sum=a-b;break;
case '*':sum=a*b;break;
case '/':sum=a/b;break;
}
cout<<"结果为"<<sum<<endl;
char m;
cout<<"输入一个整数"<<endl;
cin>>a;
cout<<"输入四则运算(+,-,*,/)"<<endl;
cin>>m;
cout<<"输入第二个整数"<<endl;
cin>>b;
switch(m)
{
case '+':sum=a+b;break;
case '-':sum=a-b;break;
case '*':sum=a*b;break;
case '/':sum=a/b;break;
}
cout<<"结果为"<<sum<<endl;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
意思是 判断操作符 才操作的么..
char op ='+';
int numA = 5, numB =6,res;
switch (op) {
case '+':
res = numA +numB;
break;
case '-':
res = numA -numB;
break;
case '*':
res = numA *numB;
break;
case '/':
try {
res = numA /numB;
} catch (Exception e) {
System.out.println("除数不能为0");
}
break;
default:
break;
}
}
char op ='+';
int numA = 5, numB =6,res;
switch (op) {
case '+':
res = numA +numB;
break;
case '-':
res = numA -numB;
break;
case '*':
res = numA *numB;
break;
case '/':
try {
res = numA /numB;
} catch (Exception e) {
System.out.println("除数不能为0");
}
break;
default:
break;
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询