編寫思路:使用switch語句來選擇運算
#include<stdio.h>
int main()
{
int x, y, z;
char c;
printf("格式為:資料運算子資料\n");
printf("請輸入:");
scanf_s("%d%c%d", &x, &c, 1, &y);//在vs2017中輸入字元型變數需要定義長度否則出錯
switch (c)
case "+":
z = x + y;
break;
case "-":
z = x - y;
case "*":
z = x * y;
case "/":
z = x / y;
default:
printf("erro!");
}
printf("%d", z);
return 0;
編寫思路:使用switch語句來選擇運算
#include<stdio.h>
int main()
{
int x, y, z;
char c;
printf("格式為:資料運算子資料\n");
printf("請輸入:");
scanf_s("%d%c%d", &x, &c, 1, &y);//在vs2017中輸入字元型變數需要定義長度否則出錯
switch (c)
{
case "+":
z = x + y;
break;
case "-":
z = x - y;
break;
case "*":
z = x * y;
break;
case "/":
z = x / y;
break;
default:
printf("erro!");
break;
}
printf("%d", z);
return 0;
}