forked from kiba518/CSharpClassicProgram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
解一元二次方程的解.txt
59 lines (59 loc) · 1017 Bytes
/
解一元二次方程的解.txt
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
using System;
class fangcheng
{
public static void Main()
{
//声名变量
double a;
double b;
double c;
double d;
double e;
double f;
double g;
double h;
double i;
double j;
double k;
Console.WriteLine("解一元二次方程");
//输入a的值
aa: Console.WriteLine("请输入a的值:");
a=double.Parse(Console.ReadLine());
//a的值不能为0
if(a==0)
{
Console.WriteLine("请注意a的值不能为0,请重新输入!");
//返回,重新输入
goto aa;
}
//输入b的值
Console.WriteLine("请输入b的值:");
b=double.Parse(Console.ReadLine());
//输入c的值
Console.WriteLine("请输入c的值:");
c=double.Parse(Console.ReadLine());
//一元二次方程的计算公式
d=b*b;
e=4*a*c;
f=d-e;
g=(int)(Math.Sqrt(f));
i=-b+g;
j=-b-g;
h=i/(2*a);
k=j/(2*a);
//判断其根的状况
if(f==0)
{
Console.WriteLine("此方程有一根为:"+h);
}
else if(f>0)
{
Console.WriteLine("此方程有二根为:"+h);
Console.WriteLine(" "+k);
}
else
{
Console.WriteLine("此方程没有根");
}
}
}