#include <stdio.h>
int main(void)
{
float a,b,ans;
char oper[5];
printf("請輸入一數 a: ");
scanf("%f",&a);
printf("請輸入一數 b: ");
scanf("%f",&b);
printf("請輸入您所要求的運算(+,-,*,/): ");
scanf("%s",oper);
while(oper[0]!='+' && oper[0]!='-' && oper[0]!='*' && oper[0]!='/')
{
printf("輸入錯誤 請重新輸入\n");
scanf("%s",oper);
}
switch(oper[0]) {
case '+' : ans = a+b;
break;
case '-' : ans = a-b;
break;
case '*' : ans = a*b;
break;
case '/' : ans = a/b;
break;
}
printf("%f%c%f=%f\n",a,oper[0],b,ans);
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.csie.ntu.edu.tw)
◆ From: 140.112.240.76
※ 編輯: shmm 來自: 140.112.240.76 (04/11 20:53)
※ 編輯: shmm 來自: 140.112.240.76 (04/11 23:06)