早教吧 育儿知识 作业答案 考试题库 百科 知识分享

VB~!得出的总和值和平均值怎样保留后面小数??不要四舍五入OptionExplicitDimi%,sum%Dima(6)AsIntegerSubIntsum()'随机生成7个1-100内的整数sum=0Fori=0To6Text1(i)=Val(Text1(i))IfText1(i)=""The

题目详情
VB ~!得出的总和值和平均值怎样保留后面小数??不要四舍五入Option Explicit Dim i%, sum% Dim a(6) As Integer Sub Intsum() '随机生成7个1-100内的整数 sum = 0 For i = 0 To 6 Text1(i) = Val(Text1(i)) If Text1(i) = "" Then Text1(i) = "0" End If sum = sum + Val(Text1(i)) '7个数的总和 a(i) = Text1(i) Next For i = 0 To 5 a(i + 1) = IIf(a(i) > a(i + 1), a(i), a(i + 1)) '得到最大值 Next sum = sum - a(6) For i = 0 To 6 a(i) = Text1(i) Next For i = 0 To 5 a(i + 1) = IIf(a(i) > a(i + 1), a(i + 1), a(i)) '得到最大值 Next sum = sum - a(6) End Sub Private Sub Form_Load() For i = 0 To 6 Text1(i) = "" Next Text2 = "" Text3 = "" End Sub Private Sub Command1_Click() '总和 Intsum Text2 = sum End Sub Private Sub Command2_Click() '平均数 Intsum Text3 = sum / 5 End Sub
▼优质解答
答案和解析
将变量设置成double类型, Dim a As Double Dim b As Integer b = 100 / 3 a = 100 / 3 MsgBox CStr(b) MsgBox CStr(a) 这个例子