怎样编程??

来源:百度知道 编辑:UC知道 时间:2024/07/04 17:42:42
请编写程序,要求输入两个运算数个一个运算符.完成加,减,乘,除.四则运算.请高手帮帮忙!!~~~

#include <stdio.h>
void main()
{
float x,y;
char op;
scanf("%f%c%f",&x,&op,&y);
switch (op)
{
case '+':printf("=%f",x+y);break;
case '-':printf("=%f",x-y);break;
case '*':printf("=%f",x*y);break;
case '/':printf("=%f",x/y);break;
default:printf("error");break;
}

}

C/C++语言:(//后面代表注释)
#include<stdio.h> //引入需要的头文件
void main() //主函数
{
float a,b,result; //声明第一个数、第二个数和结果三个变量
char method; //声明运算符变量
printf("Enter the first number:"); //提示输入第一个数
scanf("%f",&a); //输入第一个数
printf("Enter the second number:"); //提示输入第二个数
scanf("%f",&b); //输入第二个数
printf("Enter the method:",%s); //提示输入运算符
scanf("%c",&method); //输入运算符
result=calc(a,b,method); //调用calc函数并取得结果
printf(