VB程序题 从键盘输入三条边A,B,C,如果能构成三角形,则计算他的面积
1个回答
展开全部
Private Function GetArea(intA As Integer, intB As Integer, intC As Integer) As Boolean
Dim intTmp As Integer
intTmp = -1 '若不是三角形,则返回-1,也可以返回其它数。
If IsBiger(intA+intB,intC) And _
IsBiger(intA+intC,intB) And _
IsBiger(intB+intC,intA) And _
IsSmaller(intA-intB,intC) And _
IsSmaller(intA-intC,intB) And _
IsSmaller(intB-intC,intA) And _
IsSmaller(intB-intA,intC) And _
IsSmaller(intC-intA,intB) And _
IsSmaller(intC-intB,intA) Then
'使用“三斜求模肢积” 计算面纯握积
intTmp = Sqr(1/4 * (intC^2 * intA^2 - ((intC^2 + intA^2 - intB^2)/2)^2))
End If
GetArea = intTmp
End Function
Private Function IsBiger(intA As Integer, intB As Integer) As Boolean
Dim isTmp As Boolean
isTmp = False
if intA > intB then isTmp = True
IsBiger = isTmp
End Function
Private Function IsSmaller(intA As Integer, intB As Integer) As Boolean
Dim isTmp As Boolean
isTmp = False
if intA <旦裤世 intB then isTmp = True
IsSmaller = isTmp
End Function
Dim intTmp As Integer
intTmp = -1 '若不是三角形,则返回-1,也可以返回其它数。
If IsBiger(intA+intB,intC) And _
IsBiger(intA+intC,intB) And _
IsBiger(intB+intC,intA) And _
IsSmaller(intA-intB,intC) And _
IsSmaller(intA-intC,intB) And _
IsSmaller(intB-intC,intA) And _
IsSmaller(intB-intA,intC) And _
IsSmaller(intC-intA,intB) And _
IsSmaller(intC-intB,intA) Then
'使用“三斜求模肢积” 计算面纯握积
intTmp = Sqr(1/4 * (intC^2 * intA^2 - ((intC^2 + intA^2 - intB^2)/2)^2))
End If
GetArea = intTmp
End Function
Private Function IsBiger(intA As Integer, intB As Integer) As Boolean
Dim isTmp As Boolean
isTmp = False
if intA > intB then isTmp = True
IsBiger = isTmp
End Function
Private Function IsSmaller(intA As Integer, intB As Integer) As Boolean
Dim isTmp As Boolean
isTmp = False
if intA <旦裤世 intB then isTmp = True
IsSmaller = isTmp
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询