vb代码编写标准平方差的代码

vb代码编写标准平方差的代码,第1张

Dim str As String = ""

        Dim a(10) As Integer

        For i = 1 To 10

            a(i) = Int(Rnd() * 90 + 10)

            str = str & a(i) & " "

        Next

        My.Computer.FileSystem.WriteAllText("1.txt", str, False)

        Dim temp As String = My.Computer.FileSystem.ReadAllText("1.txt")

        Dim b() As String = Split(temp, " ")

        Dim avg, sum, res, pm As Double

        sum = 0

        pm = 0

        For i = 1 To UBound(b)

            sum = sum + Val(b(i))

      哪尺源困羡  Next

        avg = sum / UBound(b)

        For i = 1 To UBound(b)

            pm = pm + (Val(b(i)) - avg) ^ 2

        Next

        str = str & "标准平方差李态是" & Sqrt(pm)

        TextBox6.Text = str

Private Sub timer1_timer()

Label2.Caption = "当前时间:" + CStr(Time)

If Text1.Text = CStr(Time) Then

MsgBox "倒计时结束"

Timer1.Enabled = False

End If

End Sub

Private Sub Form_load()

Timer1.Enabled = False

Timer1.Interval = 1000

Command1.Caption = "开始计时"

Command2.Caption = "计算差值"

Command3.Caption = "计算出现次数"

Text2.Text = Date '为测试方便,就设了一初值

Text3.Text = "2009-5-30" '为渣肆测试方便,就设了一初值

End Sub

Private Sub command1_click()

Timer1.Enabled = True

End Sub

Private Sub command2_click()

Dim dt As Date

dt = CDate(Text2.Text) - CDate(Text3.Text)

Text4.Text = CStr(CInt(dt))

End Sub

Private Sub command3_click()

Dim a, b, c, len_str As Integer

Dim str As String

a = 0

b = 0

c = 0

str = Text5.Text

len_str = Len(str)

For i = 1 To len_str

Select Case Left(str, 1)

Case "a"

a = a + 1

Case "b"

b = b + 1

Case "c"

c = c + 1

End Select

str = Right(str, len_str - i)

Next i

Print "a共出现" &CStr(a) &"次"

Print "b共出现" &CStr(b) &"次"

Print "c共出现" &CStr(c) &"次"

End

'缺梁猜用数组统计.不太明白你意思.没实现

'程序中有几个都是设伏型了初值的,主要是为了测试的时候方便.你可用可不用

'大概测试了一下没什么问题,你再看看吧!


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12237147.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-22
下一篇 2023-05-22

发表评论

登录后才能评论

评论列表(0条)

保存