一元二次方程vb源码(vb二元一次方程组求解)
本文目录一览:
- 1、用vb编写一个一元二次方程
- 2、用VB编写求一元二次方程的代码是什么?
- 3、VB 解一元二次方程程序设计
- 4、用VB怎么编一元二次方程计算?
- 5、求解一元二次方程的程序vb
- 6、vb6.0解一元二次方程代码
用vb编写一个一元二次方程
在窗口上新建一个按钮一元二次方程vb源码,代码如下一元二次方程vb源码:
Private Sub Command1_Click()
Dim a As Single
Dim b As Single
Dim c As Single
Dim x As Single
Dim y As Single
a = Val(InputBox("请输入a", "参数a"))
b = Val(InputBox("请输入b", "参数b"))
c = Val(InputBox("请输入c", "参数c"))
x = Val(InputBox("请输入x", "参数x"))
y = a * x ^ 2 + b * x + c
Print "y=" a "* " x "^2+" b "*" x "+" c "=" y
End Sub
用VB编写求一元二次方程的代码是什么?
'求一元二次方程的跟ax^2+bx+c=0
Private Sub Command1_Click()
Dim a#, b#, c#, gen#
a = InputBox("输入A的值")
b = InputBox("输入B的值")
c = InputBox("输入C的值")
If a = 0 And b = 0 And c = 0 Then
Print "x的值是全体实数."
ElseIf a = 0 And b = 0 And c 0 Then
Print "x的值不存在!"
ElseIf a = 0 And b 0 Then
Print "x1的值是"; (-c / b)
ElseIf a 0 And (b ^ 2 - 4 * a * c) = 0 Then
gen = (b ^ 2 - 4 * a * c) ^ 0.5
Print "x1的值是"; ((-b - gen) / (2 * a))
Print "x2的值是"; ((-b + gen) / (2 * a))
ElseIf a 0 And (b ^ 2 - 4 * a * c) 0 Then
Print "x的值不存在!"
End If
End Sub
VB 解一元二次方程程序设计
vb代码如下:
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
Dim d As Single, x1 As Single, x2 As Single
a = InputBox("请输入一元二次方程的系数a")
b = InputBox("请输入一元二次方程的系数b")
c = InputBox("请输入一元二次方程的系数c")
If a = 0 Then
a = InputBox("因为a≠0,你输入的a=0,请重新输入系数a")
End If
d = b * b - 4 * a * c
If d = 0 Then
x1 = (-b + Sqr(d)) / (2 * a)
x2 = (-b - Sqr(d)) / (2 * a)
Print "系数为"; a; b; c; "的一元二次方程的根分别为"; x1
Print "系数为"; a; b; c; "的一元二次方程的根分别为"; x2
Else
Print "此方程在实数范围内无解"
End If
End Sub
一、按钮“求一元二次方程”的vb代码如下:
Private Sub Command1_Click()
a = Text1.Text
b = Text2.Text
c = Text3.Text
d = b * b - 4 * a * c
If d = 0 Then
X1 = (-b + Sqr(d)) / (2 * a)
X2 = (-b - Sqr(d)) / (2 * a)
Label4.Caption = X1
Label5.Caption = X2
Else
Label4.Caption = "在实数范围内无解"
End If
End Sub
二、按钮“重置”的vb代码如下:
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Label4.Caption = ""
Label5.Caption = ""
End Sub
三、按钮“退出”的vb代码如下:
Private Sub Command3_Click()
End
End Sub
特殊例子(指定系数c的值为5):
在窗体“Form1.frm”的“Command1_click“事件中编写代码(请不要随便更改其它代码),使之能够实现如下功能:在Text1输入整数a、、Text2输入b,判断一元二次方程ax2+bx+5=0有无实数根。并在Text3文本框中显示判断结果,即有实数根则在Text3文本框中输出“有”,否则输出“无”。
VB程序代码如下:
Private Sub Command1_Click()
dim a as single,b as single
a = Text1.Text
b = Text2.Text
d = b * b - 4 * a * 5
If d = 0 Then
Text3.Text="有"
Else
Text3.Text="无"
End If
End Sub
如果不用dim定义变量,则上面的输入部分语句改为下面的语句,这样可以把字符变量类型转化为数值类型:
a =val(Text1.Text)
b =val(Text2.Text)
楼主.给你写这么呢多你不给加点分吗?= =||
用VB怎么编一元二次方程计算?
创建text1,text2,text3
dim a,b,c,x1,x2 '声明变量
val(text1.text)=a
val(text2.text)=b
val(text3.text)=c '给变量赋值
if b^2-4ac=0 then
x1=(-b+sqr(b^2-4ac))/2a
x2=(-b-sqr(b^2-4ac))/2a '利用求根公式计算
print "方程的解为:" x1 ";" x2
else
print "方程没有实数解"
end if '判断并输出结果
求解一元二次方程的程序vb
直接将代码复制到窗体中测试即可Private Sub Form_Load()
Dim a, b, c, x1, x2 As Single
Dim str As String
a = Val(InputBox("请输入一元二次方程的二次项系数"))
b = Val(InputBox("请输入一元二次方程的一次项系数"))
c = Val(InputBox("请输入一元二次方程的常数项"))
If a = 0 Then
If c 0 Then
str = b "x" c "=0"
Else
str = b "x+" c "=0"
End If
If MsgBox("你输入的方程为" str ",是否要求解?", vbOKCancel) = vbOK Then
If b = 0 Then
MsgBox "此方程无解!"
Else
x1 = -c / b
MsgBox "方程只有一个解,x=" x1
End If
End If
Else
If b 0 Then
If c 0 Then
str = a "x^2" b "x" c "=0"
Else
str = a "x^2" b "x+" c "=0"
End If
Else
If c 0 Then
str = a "x^2+" b "x" c "=0"
Else
str = a "x^2+" b "x+" c "=0"
End If
End If
If MsgBox("你输入的方程为" str ",是否要求解?", vbOKCancel) = vbOK Then
If b ^ 2 - 4 * a * c 0 Then
MsgBox "方程" str "无解!"
Else
If b ^ 2 - 4 * a * c = 0 Then
x1 = (-b + Sqr(b ^ 2 - 4 * a * c)) / (2 * a)
MsgBox "方程" str "有两个相等的解,x1=" x1 ",x2=" x1
Else
x1 = (-b + Sqr(b ^ 2 - 4 * a * c)) / (2 * a)
x2 = (-b - Sqr(b ^ 2 - 4 * a * c)) / (2 * a)
MsgBox "方程" str "有两个不相等的解,x1=" x1 ",x2=" x2
End If
End If
End If End If
End
End Sub
vb6.0解一元二次方程代码
有问题,2*a要加括号。
最好先判断一下a是否为0。
还可以把复根算出来。
程序如下
Dim a, b, c As Double
Let a = Val(Text1.Text)
Let b = Val(Text2.Text)
Let c = Val(Text3.Text)
If a = 0 Then
Let Text4.Text = -c / b
Let Text5.Text = "非一元二次方程,仅有一解"
Else
If b ^ 2 - 4 * a * c = 0 Then
Let Text4.Text = (-b + Sqr(b ^ 2 - 4 * a * c)) / (2 * a)
Let Text5.Text = (-b - Sqr(b ^ 2 - 4 * a * c)) / (2 * a)
Else
Let Text4.Text = Str(-b / (2 * a)) "+" Str(Sqr(4 * a * c - b ^ 2) / (2 * a)) "i"
Let Text5.Text = Str(-b / (2 * a)) "-" Str(Sqr(4 * a * c - b ^ 2) / (2 * a)) "i"
End If
End If