初学者问题:如何在VB中用3个“if...then”或者2个“if...then...else”解二元一次方程?
如题,如何在VisualBasic6中分别用(1)if...then...if...then...if...then...和(2)if...then...if...the...
如题,如何在Visual Basic 6中分别用
(1)if...then...
if...then...
if...then...
和
(2)if...then...
if...then...
else
end if
else
end if
这两种方法解二元一次方程(直线方程)。分别计算出当两直线平行、重合、相交3种情况的X、Y的值。
只要用简单的就可以了,适合我初学者的水平。以下是我做的
Private Sub Command1_Click()
Dim a1, a2, a3, b1, b2, b3, c1, c2, c3, x1, x2 As Single
a1 = InputBox("请输入a1=", "a1")
b1 = InputBox("请输入a1=", "b1")
c1 = InputBox("请输入a1=", "c1")
a2 = InputBox("请输入a1=", "a2")
b2 = InputBox("请输入a1=", "b2")
c2 = InputBox("请输入a1=", "c2")
If (a1 / a2) <> (b1 / b2) Then
x = (b1 * c2 - b2 * c1) / (a2 * b1 - a1 * b2)
y = (a1 * c2 - a2 * c1) / (b2 * a1 - a2 * b1)
Print "解得x="; x, "解得y="; y
End If
If (a1 / a2) = (c1 / c2) Then
Print "方程无解"
End If
End Sub
就是永上面的两种格式套进去。
万分感谢,我会追加分数的!!!
第二种格式中的第二个if...t中间的
if...then...
else
end if 是相关联的,这三个前面都有空格
就是改变if语句的格式! 展开
(1)if...then...
if...then...
if...then...
和
(2)if...then...
if...then...
else
end if
else
end if
这两种方法解二元一次方程(直线方程)。分别计算出当两直线平行、重合、相交3种情况的X、Y的值。
只要用简单的就可以了,适合我初学者的水平。以下是我做的
Private Sub Command1_Click()
Dim a1, a2, a3, b1, b2, b3, c1, c2, c3, x1, x2 As Single
a1 = InputBox("请输入a1=", "a1")
b1 = InputBox("请输入a1=", "b1")
c1 = InputBox("请输入a1=", "c1")
a2 = InputBox("请输入a1=", "a2")
b2 = InputBox("请输入a1=", "b2")
c2 = InputBox("请输入a1=", "c2")
If (a1 / a2) <> (b1 / b2) Then
x = (b1 * c2 - b2 * c1) / (a2 * b1 - a1 * b2)
y = (a1 * c2 - a2 * c1) / (b2 * a1 - a2 * b1)
Print "解得x="; x, "解得y="; y
End If
If (a1 / a2) = (c1 / c2) Then
Print "方程无解"
End If
End Sub
就是永上面的两种格式套进去。
万分感谢,我会追加分数的!!!
第二种格式中的第二个if...t中间的
if...then...
else
end if 是相关联的,这三个前面都有空格
就是改变if语句的格式! 展开
展开全部
'都没有考虑 除数为零的情况,可以改成a1*b2=a2*b1的形式
Private Sub Command1_Click()
Dim a1, a2, a3, b1, b2, b3, c1, c2, c3, x1, x2 As Single
a1 = InputBox("请输入a1=", "a1")
b1 = InputBox("请输入b1=", "b1")
c1 = InputBox("请输入c1=", "c1")
a2 = InputBox("请输入a2=", "a2")
b2 = InputBox("请输入b2=", "b2")
c2 = InputBox("请输入c2=", "c2")
If (a1 / a2) <> (b1 / b2) Then
x = (b1 * c2 - b2 * c1) / (a2 * b1 - a1 * b2)
y = (a1 * c2 - a2 * c1) / (b2 * a1 - a2 * b1)
Print "解得x="; x, "解得y="; y
ElseIf (a1 / a2) = (b1 / b2) And (a1 / a2) <> (c1 / c2) Then
Print "方程无解(平行)"
Else
Print "方程有无数多解(两直线重合)"
End If
End Sub
'或者
Private Sub Command1_Click()
Dim a1, a2, a3, b1, b2, b3, c1, c2, c3, x1, x2 As Single
a1 = InputBox("请输入a1=", "a1")
b1 = InputBox("请输入b1=", "b1")
c1 = InputBox("请输入c1=", "c1")
a2 = InputBox("请输入a2=", "a2")
b2 = InputBox("请输入b2=", "b2")
c2 = InputBox("请输入c2=", "c2")
If (a1 / a2) <> (b1 / b2) Then
x = (b1 * c2 - b2 * c1) / (a2 * b1 - a1 * b2)
y = (a1 * c2 - a2 * c1) / (b2 * a1 - a2 * b1)
Print "解得x="; x, "解得y="; y
If (a1 / a2) = (b1 / b2) And (a1 / a2) <> (c1 / c2) Then
Print "方程无解(平行)""
End If
If (a1 / a2) = (b1 / b2) And (a1 / a2) = (c1 / c2) Then
Print "方程有无数多解(两直线重合)"
End If
End Sub
Private Sub Command1_Click()
Dim a1, a2, a3, b1, b2, b3, c1, c2, c3, x1, x2 As Single
a1 = InputBox("请输入a1=", "a1")
b1 = InputBox("请输入b1=", "b1")
c1 = InputBox("请输入c1=", "c1")
a2 = InputBox("请输入a2=", "a2")
b2 = InputBox("请输入b2=", "b2")
c2 = InputBox("请输入c2=", "c2")
If (a1 / a2) <> (b1 / b2) Then
x = (b1 * c2 - b2 * c1) / (a2 * b1 - a1 * b2)
y = (a1 * c2 - a2 * c1) / (b2 * a1 - a2 * b1)
Print "解得x="; x, "解得y="; y
ElseIf (a1 / a2) = (b1 / b2) And (a1 / a2) <> (c1 / c2) Then
Print "方程无解(平行)"
Else
Print "方程有无数多解(两直线重合)"
End If
End Sub
'或者
Private Sub Command1_Click()
Dim a1, a2, a3, b1, b2, b3, c1, c2, c3, x1, x2 As Single
a1 = InputBox("请输入a1=", "a1")
b1 = InputBox("请输入b1=", "b1")
c1 = InputBox("请输入c1=", "c1")
a2 = InputBox("请输入a2=", "a2")
b2 = InputBox("请输入b2=", "b2")
c2 = InputBox("请输入c2=", "c2")
If (a1 / a2) <> (b1 / b2) Then
x = (b1 * c2 - b2 * c1) / (a2 * b1 - a1 * b2)
y = (a1 * c2 - a2 * c1) / (b2 * a1 - a2 * b1)
Print "解得x="; x, "解得y="; y
If (a1 / a2) = (b1 / b2) And (a1 / a2) <> (c1 / c2) Then
Print "方程无解(平行)""
End If
If (a1 / a2) = (b1 / b2) And (a1 / a2) = (c1 / c2) Then
Print "方程有无数多解(两直线重合)"
End If
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
就是改一下if语句的形式?= =
If (a1 / a2) <> (b1 / b2) Then
x = (b1 * c2 - b2 * c1) / (a2 * b1 - a1 * b2)
y = (a1 * c2 - a2 * c1) / (b2 * a1 - a2 * b1)
Print "解得x="; x, "解得y="; y
elseif (a1 / a2) = (c1 / c2) Then
Print "方程无解"
else
Print "方程有无数多解(两直线重合)"
End If
If (a1 / a2) <> (b1 / b2) Then
x = (b1 * c2 - b2 * c1) / (a2 * b1 - a1 * b2)
y = (a1 * c2 - a2 * c1) / (b2 * a1 - a2 * b1)
Print "解得x="; x, "解得y="; y
elseif (a1 / a2) = (c1 / c2) Then
Print "方程无解"
else
Print "方程有无数多解(两直线重合)"
End If
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
完全看不懂你的意思 你把计算出当两直线平行、重合、相交3种情况的X、Y的值的方程式(或者公式)写出来吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
您说的太乱了。不懂。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询