用vb做:输入一元二次方程ax^2+bx+c=0的系数abc,计算并输出一元二次方程的两个根x1,x2
7个回答
展开全部
<script language="VBScript">
dim a,b,c,k
a=cint(inputbox("请输入a的值:"))
b=cint(inputbox("请输入b的值:"))
c=cint(inputbox("请输入c的值:"))
k=b*b-4*a*c
if k<0 then
document.write "方程无实解!"
elseif k=0 then
document.write "方程有一个解:"&-b/(2*a)
else
document.write "方程有两个解x1="&(-b+sqr(k))/(2*a)&" "&"x2="&(-b-sqr(k))/(2*a)
end if
</script>
dim a,b,c,k
a=cint(inputbox("请输入a的值:"))
b=cint(inputbox("请输入b的值:"))
c=cint(inputbox("请输入c的值:"))
k=b*b-4*a*c
if k<0 then
document.write "方程无实解!"
elseif k=0 then
document.write "方程有一个解:"&-b/(2*a)
else
document.write "方程有两个解x1="&(-b+sqr(k))/(2*a)&" "&"x2="&(-b-sqr(k))/(2*a)
end if
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim a As Integer, b As Integer, c As Integer, d As Single, f As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
d = b * b - 4 * a * c
If a <> 0 Then
If d > 0 Then
Text4.Text = (-b + Sqr(d)) / (2 * a)
Text5.Text = (-b - Sqr(d)) / (2 * a)
ElseIf d = 0 Then
Text4.Text = -b / (2 * a)
Text5.Text = -b / (2 * a)
Else
Text4.Text = -b / (2 * a) & "+" & Sqr(Abs(d)) / (2 * a) & "i"
Text5.Text = -b / (2 * a) & "-" & Sqr(Abs(d)) / (2 * a) & "i"
End If
Else
If b = 0 Then
MsgBox "方程无意义,请重新输入", 48, "输入错误"
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
Else
Text4.Text = -c / b
Text5.Text = -c / b
End If
End If
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text1.SetFocus
End Sub
Private Sub Command3_Click()
End
End Sub
,求加分啊朋友
Dim a As Integer, b As Integer, c As Integer, d As Single, f As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
d = b * b - 4 * a * c
If a <> 0 Then
If d > 0 Then
Text4.Text = (-b + Sqr(d)) / (2 * a)
Text5.Text = (-b - Sqr(d)) / (2 * a)
ElseIf d = 0 Then
Text4.Text = -b / (2 * a)
Text5.Text = -b / (2 * a)
Else
Text4.Text = -b / (2 * a) & "+" & Sqr(Abs(d)) / (2 * a) & "i"
Text5.Text = -b / (2 * a) & "-" & Sqr(Abs(d)) / (2 * a) & "i"
End If
Else
If b = 0 Then
MsgBox "方程无意义,请重新输入", 48, "输入错误"
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
Else
Text4.Text = -c / b
Text5.Text = -c / b
End If
End If
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text1.SetFocus
End Sub
Private Sub Command3_Click()
End
End Sub
,求加分啊朋友
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
dim a ,b,c,x
a =val(inputbox("请输入系数a"))
b =val(inputbox("请输入系数b"))
c =val(inputbox("请输入系数c"))
……
让我想想先
a =val(inputbox("请输入系数a"))
b =val(inputbox("请输入系数b"))
c =val(inputbox("请输入系数c"))
……
让我想想先
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个太容易了把...
d=b^2-4*a*c
判断d>0 =0 <0 就有多少个解
x1=(b^2+sqr(d))/2
x2=(b^2-sqr(d))/2
d=b^2-4*a*c
判断d>0 =0 <0 就有多少个解
x1=(b^2+sqr(d))/2
x2=(b^2-sqr(d))/2
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询