33,311
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Ax^2+Bx+c=0 */
#include <math.h>
int main()
{
float a, b, c;
float delta;
float x1, x2;
printf("Input a\n");
scanf("%f", &a);
printf("Input b\n");
scanf("%f", &b);
printf("Input c\n");
scanf("%f", &c);
delta = b*b - 4 * a*c;
if (delta > 0)
{
x1 = (-b + sqrt(delta)) / (2 * a);
x2 = (-b - sqrt(delta)) / (2 * a);
printf("Two solution : x1=%f,x2=%f\n", x1, x2);
}
else if (delta = 0)
{
x1 = x2 = (-b) / (2 * a);
printf("One solution : x1=x2=%f\n", x1, x2);
}
else
{
printf("There is no solution.\n");
}
system("pause");
return 0;
}
else if (delta = 0)
这不是判断语句吧
另外浮点数与0比较大小,不能直接比较。
https://www.cnblogs.com/xiehongfeng100/p/4851201.html[/quote]
疏忽了,多谢提醒,比较那块应该是这样的:
else if (delta < 0.000001 && delta > -0.000001)
else if (delta = 0)
这不是判断语句吧
另外浮点数与0比较大小,不能直接比较。
https://www.cnblogs.com/xiehongfeng100/p/4851201.html