用VB编程:随机产生10个0~100之间的随机整数,存放在一个数组中,然后求
Private Sub Form_Load()
Dim a(10), i, x, j As Integer
Dim y As String
For i = 0 To 9
Randomize
a(i) = Int(Rnd(1) * 101)
x = x + a(i)
Next i
Print "元素和=" & x
Print "平均值=" & x / 10
For i = 0 To 9
If a(i) > (x / 10) Then j = j + 1: y = y & CStr(a(i)) & " "
Next i
Print "大于平均值的元素个数=" & j
Print "大于平均值的元素:" & y
Me.Refresh
End Sub
private
sub
command3_click()
'用vb编程:随机产生10个0~100之间的随机整数,存放在一个数组中,
'然后求个元素和、平均值,统计
'大于平均值的元素个数并把它们显示出来?
dim
myvalue(100)
as
integer
dim
i
as
integer
dim
n
as
integer
dim
sum
as
double
dim
ave
as
double
n
=
100
sum
=
0
ave
=
0
for
i
=
1
to
n
myvalue(i)
=
int(100
*
rnd)
'
生成
0
到
6
之间的随机数值。
sum
=
sum
+
myvalue(i)
next
i
ave
=
sum
/
n
for
i
=
1
to
n
if
myvalue(i)
>
ave
then
print
myvalue(i)
end
if
next
i
end
sub
用vb怎样生成10个不重复的(1到10)随机数?
vb生成10个不重复的随机数代码:Private Sub Command1_Click()Dim a(9) As Integer For i = 0 To 9 GoTo way1 End If Next p End If Print a(i)Next i End Sub
用VB语言求随机产生并显示10个1~10之间的整数,分别求出其中的所有奇数...
Dim s(10) As Integer Dim sum1 As Integer = 0 Dim sum2 As Integer = 0 For i As Integer = 1 To 10 s(i) = CInt(Int((10 * Rnd()) + 1))Next For i As Integer = 1 To 10 If s(i) Mod 2 = 0 Then sum1 += s(i)Else sum2 += s(i)End If Me.TextBox4.T...
写vb程序:随机生成10个数,保存在一维数组中,显示最大数及位置
Private Sub Form_Paint()Dim a(1 To 10) As Double Dim i As Integer, n As Integer, m As Double m = 0 Randomize For i = 1 To 10 a(i) = Rnd If m < a(i) Then m = a(i)n = i End If Print i, a(i)Next Print Print Print "第", n, m, "最大"End Sub ...
用vb设计出随机出10道10以内的加减法,怎么写程序?
Private Sub Command1_Click()Randomize Dim a(10) As Integer, b(10) As Integer Dim c As Integer For i = 0 To 9 a(i) = Int(Rnd * 10)b(i) = Int(Rnd * 10)c = Int(Rnd * 2)If c = 0 Then Print a(i) & " + " & b(i) & " = " & a(i) + b(i)Else ...
vb编程完成10个随机数的降序 要求用数组先产生10个随机数,然后排序输 ...
Private Sub RandomizeAndSort() Dim a(1 To 10) As Integer Dim i As Integer, j As Integer ' 生成 10 个整数类型的随机数 Randomize For i = 1 To 10 a(i) = Int(Rnd * 90) + 10 Next '显示 Debug.Print "排序前" For i = 1 To 10 Debug...
VB随机产生10个数字
Private Sub Form_Load()Me.AutoRedraw = True Dim rndnum(10) As Integer, tochange As Integer '产生十个两位随机数,并输出 Me.Print "原始的十个数是:"For i = 1 To 10 Randomize rndnum(i) = Int(Rnd * 51) + 0 Me.Print rndnum(i)Next i For i = 1 To 10 For j = 1 ...
vb编程:随机产生10个0~100之间的数放到一个一维数组中,将10个数从小...
Private Sub Form_Load()Dim arr(1 To 10), i, j, tmp Me.AutoRedraw = True Randomize For i = 1 To 10 arr(i) = Int(Rnd * 101)Print arr(i);Next i Print For i = 1 To 10 For j = i + 1 To 10 If arr(i) > arr(j) Then tmp = arr(i)arr(i) = arr(j)arr...
vb随机产生10个数字并把这些数字累加
代码如下 产生10个随机数字 a 累加值b Private Sub Command1_Click()Dim i As Integer, a As Integer, b As IntegerFor i = 1 To 10 a = Int(Rnd * 100) Print a b = b + aNext iPrint bEnd Sub
用vb怎样生成10个不重复的(1到10)随机数
dim a(1 to 10)for i=1 to 10 a(i)=rnd*10+1 next i
vbs怎么产生0-10的随机数呀?
vbs是vb的子集 所以共通的 看下下面的函数 你就明白了 VB随机函数:rnd()函数随即产生一个大于等于0但小于1的单精度浮点数 为了生成某个范围内的随机整数,可使用以下公式: Int((upperbound - lowerbound + 1) * Rnd + lowerbound) 这里,upperbound 是随机数范围的上限,而 lowerbound ...