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
意法半导体(中国)投资有限公司
2023-06-12 广告
2023-06-12 广告
单片机汇编程序是用汇编语言编写的程序,用于控制单片机的操作。汇编语言是一种比较接近计算机硬件语言的低级语言,相对于高级语言来说更容易理解和实现。下面是单片机汇编程序的基本步骤:1. 将代码和数据汇编到规定的段中。2. 在存储器中用未初始化的...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询