-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfangcheng.c
70 lines (37 loc) · 861 Bytes
/
fangcheng.c
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<windows.h>
#define M 0.00000000001
int main()
{
//2.写程序求一元二次方程的解
double a, b, c, disc, res1, res2;
printf("请输入一元二次方程各项的系数:\n");
scanf_s("%lf%lf%lf", &a, &b, &c);
if (a >= (-M) && a <= M)
{
printf("您输入的不是一元二次方程,程序退出\n");
}
else
{
disc = b*b - 4 * a*c;
if (disc > 0)
{
res1 = (-b + sqrt(disc)) / (2 * a);
res2 = (-b - sqrt(disc)) / (2 * a);
printf("此方程的两个根分别为 res1 = %lf res2 = %lf \n", res1, res2);
}
if (disc >= (-M) && disc <= (M))
{
res1 = -b / (2 * a);
res2 = res1;
printf("此方程有两个重根 res1 = res2 = %lf\n", res1);
}
if (disc < 0)
{
printf("此方程无解!!!\n");
}
}
system("pause");
return 0;
}