两个数的+、一、*、/简易计算器程序。并打印出 102/37 和 102-37 的结果
提示:
main()
{float X, y;
char op;
printf(”输入两个数:”):
scanf("%f,%f",&x,&y);
printf("输入运算符:");
scanf("%c”,&op):
switch (op)
{case ’+’: jexty; printf(”结果=N9.4f\n”,j):break;
case '-':......
case '*’.......
case ’/’:判断除法的计算条件。
解题思路:定义一个函数来实现该算数过程。(函数内判断所输入两数之间的符,在分别进行计算,输出即可。)
#include <stdio.h>
int main()
{
float x,y,j;
char op;
printf("输入运算:");
scanf("%f%c%f",&x,&op,&y);
switch(op)
{
case '+':j=x+y;printf("结果=%9.4f\n",j);break;
case '-':j=x-y;printf("结果=%9.4f\n",j);break;
case '*':j=x*y;printf("结果=%9.4f\n",j);break;
case '/': if (y!=0){j=x/y;printf("结果=%9.4f\n",j);}else {printf("错误"); };break;
};
return 0;
}