注册 登录
编程论坛 VB.NET论坛

大哥们,请教一下

hukaibao2007 发布于 2008-10-22 23:11, 1241 次点击
编写
求Sn=a+aa+aaa+…+aa…aaa(n个a),其中a是一个有随机数产生的1~9(包括1,9)中的一个整数,n是一个有随机数产生的5~10(包括5,10)中的一个数。
例如:当a=2,n=5时,Sn=2+22+222+2222+22222

[[it] 本帖最后由 hukaibao2007 于 2008-10-22 23:13 编辑 [/it]]
4 回复
#2
tfnpghl2008-10-23 10:06
Dim ov1, ov2 As Integer
        ov1 = Rnd() * 10 - 1 + 1
        ov2 = Rnd() * 10 - 5 + 5
        MsgBox(ov1.ToString & "- " & ov2.ToString)
        Dim str As String = ""
        For i As Integer = 0 To ov2
            For j As Integer = 0 To (i + 1)
                str += CStr(ov1)
            Next

            str += IIf(i = ov2, "", "+")
        Next
        MsgBox(str)
#3
fairy42008-10-23 13:46
[bo][un]tfnpghl[/un] 在 2008-10-23 10:06 的发言:[/bo]

Dim ov1, ov2 As Integer
        ov1 = Rnd() * 10 - 1 + 1
        ov2 = Rnd() * 10 - 5 + 5
        MsgBox(ov1.ToString & "- " & ov2.ToString)
        Dim str As String = ""
        For i As Intege ...

不用试,你的肯定不行
#4
rimke2008-10-24 09:09
顶一下
#5
ecjob2008-10-24 20:14
Randomize()
        Dim o_inta As Integer = Int((9 - 1 + 1) * Rnd() + 1), o_intn As Integer = Int((10 - 5 + 1) * Rnd() + 5), o_log结果 As Long = 0
        For o_intCount As Integer = 0 To o_intn - 1
            Dim o_strInt As String = ""
            For o_intItem As Integer = 0 To o_intCount
                o_strInt = o_strInt & o_inta
            Next
            o_log结果 = o_log结果 + Val(o_strInt)
        Next
        MsgBox("a=" & o_inta & " n=" & o_intn & " Sn=" & o_log结果, MsgBoxStyle.Information, Me.Text)
1