![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
c语言简单程序编写?
2.用户输入的是一个等式
3.程序对计算结果进行正确与否的判断,正确则输出perfect,错误则输出error
求c语言大神给个代码,我这样的c小白压根不会啊! 展开
#include<stdio.h>
int main()
{
double num1, num2, result, re;
char sign, euq;
printf("Enter an expression: ");
while(scanf("%lf%c%lf%c%lf", &num1,&sign,&num2,&euq,&result) == 5)
{
switch(sign)
{
case '+':
re = num1 + num2;
break;
case '-':
re = num1 - num2;
break;
case '*':
re = num1 * num2;
break;
case '/':
if(num2 != 0)
re = num1 / num2;
break;
}
if( re == result)
printf("Perfect.\n");
else
printf("Error\n");
printf("Enter an expression: ");
}
return 0;
}
int main()
{
float x, y, z;
char c, d;
scanf("%f%c%f%c%f", &x, &c, &y, &d, &z);
switch(c)
{
case '+':
if ((x + y) == z)
printf("perfect\n");
else
printf("error\n");
break;
case '-':
if ((x - y) == z)
printf("perfect\n");
else
printf("error\n");
}
return 0;
}