已经测试,运行正常,先输入两个数,然后输入+-*/中的一个:接着就有结果
#include
#include
int main(void)
{
float a, b;
char c;
float res;
scanf("%f %f\n", &a, &b);
c = getchar();
switch (c)
{
case '+':
res = a + b;
break;
case '-':
res = a - b;
break;
case '*':
res = a * b;
break;
case '/':
res = a / b;
break;
default:
printf("input error\n");
}
printf("result is: %f\n", res);
return 0;
}
#include
#include
int jia(int a,int b)
{
return a+b;
}
int jian(int a, int b)
{
return a-b;
}
int cheng(int a,int b)
{
return a*b;
}
int chu(int a,int b)
{
return a/b;
}
main()
{
int a,b,s;
char choice;
printf("请输入两个数 a,b:");
scanf("%d%d",&a,&b);
printf("请输入运算符:");
scanf("%c",&choice);
switch(choice)
{ case '+':jia(a,b);
case '-':jian(a,b);
case '*':cheng(a,b);
case '/':chu(a,b);
}
printf("%.2f",s);
printf("\n ok。。");
}
声明几个变量请用户输入,在给出结果就行了吧..