VB求三角形面积
给定三角形的3条边长,计算三角形的面积。编写程序,首先判断给出的3条边能否构成三角形,如可以构成,则计算并输出该三角形的面积,否则要求重新输入。当输入-1时介绍程序。--...
给定三角形的3条边长,计算三角形的面积。编写程序,首先判断给出的3条边能否构成三角形,如可以构成,则计算并输出该三角形的面积,否则要求重新输入。当输入-1时介绍程序。
-------------------------------------------------------
请问高手是否可以通过弹出框来输入长度!!还有注意下最后句话啊!! 展开
-------------------------------------------------------
请问高手是否可以通过弹出框来输入长度!!还有注意下最后句话啊!! 展开
4个回答
展开全部
代码如下。
==============
Private Sub Form_Load()
Do
Dim a As Single, b As Single, c As Single, p As Single, s As Single
a = Val(InputBox("请输入三角形第1条边长"))
If a = -1 Then Exit Do
b = Val(InputBox("请输入三角形第2条边长"))
If b = -1 Then Exit Do
c = Val(InputBox("请输入三角形第3条边长"))
If c = -1 Then Exit Do
p = (a + b + c) / 2
If a >= p Or b >= p Or c >= p Then
MsgBox "不能构成三角形"
Else
s = Sqr(p * (p - a) * (p - b) * (p - c))
MsgBox "面积为" & s
End If
Loop
End
End Sub
==============
Private Sub Form_Load()
Do
Dim a As Single, b As Single, c As Single, p As Single, s As Single
a = Val(InputBox("请输入三角形第1条边长"))
If a = -1 Then Exit Do
b = Val(InputBox("请输入三角形第2条边长"))
If b = -1 Then Exit Do
c = Val(InputBox("请输入三角形第3条边长"))
If c = -1 Then Exit Do
p = (a + b + c) / 2
If a >= p Or b >= p Or c >= p Then
MsgBox "不能构成三角形"
Else
s = Sqr(p * (p - a) * (p - b) * (p - c))
MsgBox "面积为" & s
End If
Loop
End
End Sub
武义菲亚伏电子有限公司
2023-06-12 广告
2023-06-12 广告
绝缘子是用来支持和固定母线与带电导体、并使带电导体间或导体与大地之间有足够的距离和绝缘。绝缘子应具有足够的电气绝缘强度和耐潮湿性能。通常在电气厂商上又大量批售.武义菲亚伏电子有限公司位于武义县东南工业园区,成立于2006年,专门致力于绝缘子...
点击进入详情页
本回答由武义菲亚伏电子有限公司提供
展开全部
1、海伦公式:p为三角形的周长的一半,而a,b,c分别为三角形三边的长度,
S=p(p-a)(p-b)(p-c)=[(a+b+c)(a+b-c)(a+c-b)(b+c-a)]/2
2、已知底边和高,计算就简单了
3、已知两边和夹角,先求出第三边,再使用第一项计算
其他的类似。源程序如下:
Option
Explicit
Dim
A
As
Double,
B
As
Double,
C
As
Double
Dim
Ja
As
Double,
Jb
As
Double,
Jc
As
Double
Dim
S
As
Double
Private
Sub
Form_Load()
S
=
S1(3,
6,
8)
'已知三边,求面积
MsgBox
"三边:3、6、8,面积是"
&
S
S
=
S1(3,
6,
C1(3,
6,
30
*
3.142
/
180))
'已知两边和夹角,求面积
MsgBox
"两边及夹角:3、6、30,面积是"
&
S
S
=
S2(3,
6)
'已知底和高,求面积
MsgBox
"底和高:3、6,面积是"
&
S
End
Sub
Private
Function
C1(A
As
Double,
B
As
Double,
Jc
As
Double)
As
Double
C1
=
Sqr(A
*
A
+
B
*
B
-
2
*
A
*
B
*
Cos(Jc))
End
Function
Private
Function
S1(A
As
Double,
B
As
Double,
C
As
Double)
As
Double
S1
=
(A
+
B
+
C)
*
(A
+
B
-
C)
*
(A
+
C
-
B)
*
(B
+
C
-
A)
/
2
End
Function
Private
Function
S2(D
As
Double,
G
As
Double)
As
Double
S2
=
D
*
G
/
2
End
Function
S=p(p-a)(p-b)(p-c)=[(a+b+c)(a+b-c)(a+c-b)(b+c-a)]/2
2、已知底边和高,计算就简单了
3、已知两边和夹角,先求出第三边,再使用第一项计算
其他的类似。源程序如下:
Option
Explicit
Dim
A
As
Double,
B
As
Double,
C
As
Double
Dim
Ja
As
Double,
Jb
As
Double,
Jc
As
Double
Dim
S
As
Double
Private
Sub
Form_Load()
S
=
S1(3,
6,
8)
'已知三边,求面积
MsgBox
"三边:3、6、8,面积是"
&
S
S
=
S1(3,
6,
C1(3,
6,
30
*
3.142
/
180))
'已知两边和夹角,求面积
MsgBox
"两边及夹角:3、6、30,面积是"
&
S
S
=
S2(3,
6)
'已知底和高,求面积
MsgBox
"底和高:3、6,面积是"
&
S
End
Sub
Private
Function
C1(A
As
Double,
B
As
Double,
Jc
As
Double)
As
Double
C1
=
Sqr(A
*
A
+
B
*
B
-
2
*
A
*
B
*
Cos(Jc))
End
Function
Private
Function
S1(A
As
Double,
B
As
Double,
C
As
Double)
As
Double
S1
=
(A
+
B
+
C)
*
(A
+
B
-
C)
*
(A
+
C
-
B)
*
(B
+
C
-
A)
/
2
End
Function
Private
Function
S2(D
As
Double,
G
As
Double)
As
Double
S2
=
D
*
G
/
2
End
Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
设三边长分别为a,b,c。
a,b,c满足a+b>c,a+c>b,b+c>a即可为三角形。
求面积用海伦公式:
S=√[p(p-a)(p-b)(p-c)]
(p为三角形半周长,p=(a+b+c)/2 )
弹出框请使用InputBox语句。
a,b,c满足a+b>c,a+c>b,b+c>a即可为三角形。
求面积用海伦公式:
S=√[p(p-a)(p-b)(p-c)]
(p为三角形半周长,p=(a+b+c)/2 )
弹出框请使用InputBox语句。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub btnInput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInput.Click
Dim dbl1 As Double = CDbl(InputBox("请输入第一条边长度:", , CStr(0)))
Dim dbl2 As Double = CDbl(InputBox("请输入第二条边长度:", , CStr(0)))
Dim dbl3 As Double = CDbl(InputBox("请输入第三条边长度:", , CStr(0)))
If dbl1 = -1 OrElse dbl2 = -1 OrElse dbl3 = -1 Then Exit Sub
If dbl1 + dbl2 <= dbl3 OrElse dbl2 + dbl3 <= dbl1 OrElse dbl1 + dbl3 <= dbl2 Then
MsgBox("输入的三边长度无法组成一个三角形!")
Else
Dim MianJi As Double
Dim P As Double = (dbl1 + dbl2 + dbl3) / 2
MianJi = Math.Sqrt(P * (P - dbl1) * (P - dbl2) * (P - dbl3))
MsgBox(MianJi)
End If
End Sub
以上是 Visual Basic 2005 的代码。
Dim dbl1 As Double = CDbl(InputBox("请输入第一条边长度:", , CStr(0)))
Dim dbl2 As Double = CDbl(InputBox("请输入第二条边长度:", , CStr(0)))
Dim dbl3 As Double = CDbl(InputBox("请输入第三条边长度:", , CStr(0)))
If dbl1 = -1 OrElse dbl2 = -1 OrElse dbl3 = -1 Then Exit Sub
If dbl1 + dbl2 <= dbl3 OrElse dbl2 + dbl3 <= dbl1 OrElse dbl1 + dbl3 <= dbl2 Then
MsgBox("输入的三边长度无法组成一个三角形!")
Else
Dim MianJi As Double
Dim P As Double = (dbl1 + dbl2 + dbl3) / 2
MianJi = Math.Sqrt(P * (P - dbl1) * (P - dbl2) * (P - dbl3))
MsgBox(MianJi)
End If
End Sub
以上是 Visual Basic 2005 的代码。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询