如何写一个能进行加减乘除的C语言程序?
展开全部
#include <stdio.h>
void main(void)
{
char operation;
float a;
float b;
double result;
printf("Please input the first number:");
scanf("%f", &a);
getchar();
printf("请输入运算符:");
scanf("%c", &operation);
getchar();
printf("Please input the second number:");
scanf("%f", &b);
switch (operation)
{
case '+': result = a + b; break;
case '-': result = a - b; break;
case '*': result = a * b; break;
case '/': result = a / b; break;
default: break;
}
printf("%f %c %f = %f\n", a, operation, b, result);
}
void main(void)
{
char operation;
float a;
float b;
double result;
printf("Please input the first number:");
scanf("%f", &a);
getchar();
printf("请输入运算符:");
scanf("%c", &operation);
getchar();
printf("Please input the second number:");
scanf("%f", &b);
switch (operation)
{
case '+': result = a + b; break;
case '-': result = a - b; break;
case '*': result = a * b; break;
case '/': result = a / b; break;
default: break;
}
printf("%f %c %f = %f\n", a, operation, b, result);
}
2012-03-17
展开全部
楼上的基本实现了,只是比较简单的功能,没有考虑很多实际情况,如除数等于0等错误情况
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询