回覆列表
-
1 # 木子李ovo
-
2 # 阡白陌雪
int main()
{
int a,b;
char ch;
printf("請輸入x=");
scanf("%d",&a);
printf("請輸入y=");
scanf("%d",&b);
printf("請輸入需要進行的運算:");
scanf("%c",&ch);
switch(ch)
case "+":
printf("x+y=%d\n",a+b);
break;
case "-":
printf("x-y=%d\n",a-b);
break;
case "*":
printf("x*y=%d\n",a*b);
break;
case "/":
if(b==0)
printf("分母不能為0\n");
else
printf("x/y=%d\n",a/b);
break;
default:
printf("輸入錯誤");
break;
return 0;
}
int main()
{
int a,b;
char ch;
printf("請輸入x=");
scanf("%d",&a);
printf("請輸入y=");
scanf("%d",&b);
printf("請輸入需要進行的運算:");
scanf("%c",&ch);
switch(ch)
case "+":
printf("x+y=%d\n",a+b);
break;
case "-":
printf("x-y=%d\n",a-b);
break;
case "*":
printf("x*y=%d\n",a*b);
break;
case "/":
if(b==0)
printf("分母不能為0\n");
else
printf("x/y=%d\n",a/b);
break;
default:
printf("輸入錯誤");
break;
return 0;
}