gpt4 book ai didi

c - 为什么这段计算二次方程解的代码不起作用?

转载 作者:太空宇宙 更新时间:2023-11-04 05:18:56 25 4
gpt4 key购买 nike

每当我尝试运行它时,它都会返回错误的解决方案,例如:
答:303
乙:405
C: 50

实解:−0.13762776465722773
我的解决方案:-110079.531250

#include <stdio.h>
#include <math.h>
int main(){
float a;
float b;
float c;
float solution;
float d;
printf("A: ");
scanf("%f", &a);
printf("B: ");
scanf("%f", &b);
printf("C: ");
scanf("%f",&c);
d = b * b - 4 * a * c;
solution = (-b - sqrt(d))/ 2*a;
printf("%f", solution);
}

最佳答案

你忘记了 BODMAS。将 (-b - sqrt(d))/2*a 替换为 (-b - sqrt(d))/(2*a)

关于c - 为什么这段计算二次方程解的代码不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20817051/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com