vb考试题目急求答案
OptionExplicit'-------------------------------------------------'【程序设计】'-------------...
Option Explicit
'-------------------------------------------------
'【程序设计】
'-------------------------------------------------
'题目:编写函数fun,函数的功能是:计算n门课程
' 的平均值,计算结果作为函数值返回。
' 例如,若有5门课程的成绩是:92,76,69,
' 58,88,则函数的值为76.6。
'-------------------------------------------------
'注意:请在指定的事件内编写代码。
'-------------------------------------------------
Private Function fun(a() As Integer, n As Integer) As Double
'********** Program *********
???
'********** End *************
End Function
Private Sub Form_Load()
Show
Dim a(5) As Integer, i As Integer
a(1) = 92: a(2) = 76: a(3) = 69: a(4) = 58: a(5) = 88
Print fun(a, 5)
WWJT
End Sub
Private Sub WWJT()
Dim i As Integer
Dim s As String
Dim l As Long
Dim d As Double
Dim a(10) As String
Dim b(5) As Integer
Dim fIn As Integer
Dim fOut As Integer
fIn = FreeFile
Open App.Path & "\in.dat" For Input As #fIn
fOut = FreeFile
Open App.Path & "\out.dat" For Output As #fOut
For i = 1 To 5
Line Input #fIn, a(i)
b(i) = Val(a(i))
Next
Print #fOut, fun(b, 5)
Close #fIn
Close #fOut
End Sub
怎么写啊急求答案 展开
'-------------------------------------------------
'【程序设计】
'-------------------------------------------------
'题目:编写函数fun,函数的功能是:计算n门课程
' 的平均值,计算结果作为函数值返回。
' 例如,若有5门课程的成绩是:92,76,69,
' 58,88,则函数的值为76.6。
'-------------------------------------------------
'注意:请在指定的事件内编写代码。
'-------------------------------------------------
Private Function fun(a() As Integer, n As Integer) As Double
'********** Program *********
???
'********** End *************
End Function
Private Sub Form_Load()
Show
Dim a(5) As Integer, i As Integer
a(1) = 92: a(2) = 76: a(3) = 69: a(4) = 58: a(5) = 88
Print fun(a, 5)
WWJT
End Sub
Private Sub WWJT()
Dim i As Integer
Dim s As String
Dim l As Long
Dim d As Double
Dim a(10) As String
Dim b(5) As Integer
Dim fIn As Integer
Dim fOut As Integer
fIn = FreeFile
Open App.Path & "\in.dat" For Input As #fIn
fOut = FreeFile
Open App.Path & "\out.dat" For Output As #fOut
For i = 1 To 5
Line Input #fIn, a(i)
b(i) = Val(a(i))
Next
Print #fOut, fun(b, 5)
Close #fIn
Close #fOut
End Sub
怎么写啊急求答案 展开
展开全部
Private Function fun(a() As Integer, n As Integer) As Double
'********** Program *********
Dim i%, allfenshu as single, pingjunfen As Single
For i = 1 To n
allfenshu = allfenshu + a(i)
Next
pingjunfen = allfenshu / n
fun = Val(Format$(pingjunfen, "0.0"))
'********** End *************
End Function
'********** Program *********
Dim i%, allfenshu as single, pingjunfen As Single
For i = 1 To n
allfenshu = allfenshu + a(i)
Next
pingjunfen = allfenshu / n
fun = Val(Format$(pingjunfen, "0.0"))
'********** End *************
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Function fun(a() As Integer, n As Integer) As Double
'********** Program *********
Dim i, sum As Integer
sum = 0
For i = LBound(a) To UBound(a)
sum = sum + a(i)
Next i
fun = sum / 5
'********** End *************
End Function
'********** Program *********
Dim i, sum As Integer
sum = 0
For i = LBound(a) To UBound(a)
sum = sum + a(i)
Next i
fun = sum / 5
'********** End *************
End Function
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Function fun(a() As Integer, n As Integer) As Double
'********** Program *********
Dim i As Integer
For i = 0 To A.Length - 1
fun += A(i)
Next
fun = fun / N
'********** End *************
End Function
'********** Program *********
Dim i As Integer
For i = 0 To A.Length - 1
fun += A(i)
Next
fun = fun / N
'********** End *************
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询