#include<stdio.h>
float calculate(float a,float b,float d,char c)
{
switch(c)
case "+":d=a+b;break;
case "-":d=a-b;break;
case "*":d=a*b;break;
case "/":d=a/b;break;
default :putchar("\a"); //若運算子號出現錯誤,則機器以發出聲音報錯,注意,單撇號不要丟了
}
return d;
int main()
float a,b,d,z;
char c;
printf("what dou you want to calculate\n");
scanf("%f %c %f",&a,&c,&b);
z=calculate(a,b,d,c);
printf("%f%c%f=%f\n",a,c,b,z);
return 0;
#include<stdio.h>
float calculate(float a,float b,float d,char c)
{
switch(c)
{
case "+":d=a+b;break;
case "-":d=a-b;break;
case "*":d=a*b;break;
case "/":d=a/b;break;
default :putchar("\a"); //若運算子號出現錯誤,則機器以發出聲音報錯,注意,單撇號不要丟了
}
return d;
}
int main()
{
float a,b,d,z;
char c;
printf("what dou you want to calculate\n");
scanf("%f %c %f",&a,&c,&b);
z=calculate(a,b,d,c);
printf("%f%c%f=%f\n",a,c,b,z);
return 0;
}