THIS IS B3c0me

记录生活中的点点滴滴

0%

求二次方程的根

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
int main()
{
double xishu1, xishu2, xishu3;
scanf("%lf %lf %lf", &xishu1, &xishu2, &xishu3);
double result1, result2;
//printf("%lf %lf %lf", xishu1, xishu2, xishu3);
if (xishu2 * xishu2 - 4 * xishu1 * xishu3 < 0) {
printf("No answer!");
return 0;
}
result1 = (-1 * xishu2 + sqrt(xishu2 * xishu2 - 4 * xishu1 * xishu3)) / (2 * xishu1);
result2 = (-1*xishu2 - sqrt(xishu2 * xishu2 - 4 * xishu1 * xishu3)) / (2 * xishu1);

if (result1==result2) {
printf("x1=x2=%.5f", result1);
}
else {
if (result1 > result2) {
printf("x1=%.5f;x2=%.5f", result2, result1);
}
if (result1 < result2) {
printf("x1=%.5f;x2=%.5f", result1, result2);
}
return 0;

}
}

欢迎关注我的其它发布渠道