关于C语言和C++的一道题

要求设计一个简单的程序,用来计算两个数的加减乘除。
要求用 switch语句或if语句

第1个回答  2007-04-02
#include <stdio.h>
#include <conio.h>
int main()
{
int x,y;
char z;
printf("Enter x:");
scanf("%d",&x);
printf("Enter y:");
scanf("%d",&y);
fflush(stdin);
printf("Enter +,-,*,/:");
scanf("%c",&z);
switch(z)
{
case '+':printf("%d\n",x+y);break;
case '-':printf("%d\n",x-y);break;
case '*':printf("%d\n",x*y);break;
case '/':printf("%d\n",x/y);break;
}
getch();
return 0;
}

参考资料:http://zhidao.baidu.com/question/21127055.html

第2个回答  2007-04-02
switch(c)
{
case "+":s=a+b;break;

case "-":s=a-b;break;

case "*":s=a*b;break;

case "/":if(b!=0)
s=a/b;
else
打印:除数不能为0
break;

}本回答被提问者采纳
相似回答
大家正在搜