|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 moc111 于 2021-1-10 14:36 编辑
#include <stdio.h>
#include <math.h>
void main()
{
double x1, x2, a, b, c, p, q, disc;
scanf_s("a=%lf,b=%lf,c=%lf", &a, &b, &c);
disc = b * b - 4 * a * c;
p = -b / (2 * a);
q = sqrt(disc) / (2 * a);
x1 = p + q;
x2 = p - q;
printf("\nx1=%5.2f\nx2=%5.2f\n", x1, x2);
}
求ax^2+bx+c=0的根,a,b,c键盘输入。————这是题目
我用的vs2019,能够运行,但是结果不对,数还特别离奇!!!
- #include <stdio.h>
- #include <math.h>
- void main()
- {
- double x1, x2, a, b, c, p, q, disc;
- scanf_s("%lf%lf%lf", &a, &b, &c); // scanf()函数除控制符外,不要添加任何的其他字符
- disc = b * b - 4 * a * c;
- p = -b / (2.0 * a);
- q = sqrt(disc) / (2 * a);
- x1 = p + q;
- x2 = p - q;
- printf("\nx1=%5.2f\nx2=%5.2f\n", x1, x2);
- }
复制代码
|
|