VB试题,6/26之前要,有能力的帮忙做以下

来源:百度知道 编辑:UC知道 时间:2024/09/28 08:50:41
1. 编写程序段,用随机函数产生10个1~100之间整数,输出最大值。
for I= 0 to 9
a(I)=int(rnd(1)*100)+1
randomize
next I
l=0
for I=1 to 9
if a(i)>a(l) then
l=I
end if
next I
‘输出a(l)

2. 编写程序,在数组A中输入10个整数,输出它们的平均值。
s=0
for I=0 to 9
a(i)=inputbox(“”)
s=s+a(i)
next I
s=s/10

3. 编写程序段,输入一个字符串,统计其中空格的个数。
str=inputbox(“”)
le=len(str)
s=0
for I=1 to le
if mid(str,i)=” ” then
s=s+1
end if
next

‘输出2

4. 编程输出1到100之间的素数。
for I=3 to 99 step 2
for j=2 to int(sqrt(i))
if I mod j =0 then
exit for
end if
next j
if j>int(sqrt(i))
‘是素数
end if
next I

I=1
S=0
Do
S=s+1/(I^2)
I=I+1
Loop until 1(I^2)<1e-5
‘输出

5. 编写程序段,计算并输出下面多项式的和,直到其中的某一项小于10-5为止。
1+1/22+1/32+……
I=1
S=0
Do
S=s+1/(I^2)
I=I+1
Loop while 1(I^2)>=1e-5
‘输出

1、编写程序段,用随机函数产生10个1~100之间整数,输出最大值。

'变量定义
Dim I,l As Integer
Dim a(9) As Integer

for I= 0 to 9
a(I)=int(rnd(1)*100)+1
randomize
next I
l=0
for I=1 to 9
if a(i)>a(l) then
l=I
end if
next I

‘输出a(l)
立即窗口Print方法:Debug.Print str(a(l))
Msgbox方法:Msgbox str(a(l))

2、编写程序,在数组A中输入10个整数,输出它们的平均值。

'变量定义
Dim I As Integer
Dim s As Long
Dim a(9) As Long

s=0
for I=0 to 9
a(i)=inputbox("")
s=s+a(i)
next I
s=s/10

'输出结果
立即窗口Print方法:Debug.Print str(s)
Msgbox方法:Msgbox str(s)

3、编写程序段,输入一个字符串,统计其中空格的个数。

'变量定义
Dim str as string
Dim le as Long
Dim s,I as Long

str=inputbox("")
le=len(str)
s=0
for I=1 to le
if mid(str,I)=" " then
s=s+1
end if
next

'输出结果