您的当前位置:首页正文

vb程序设计例题

2024-06-19 来源:步旅网


1 下列哪个程序段可以分别显示1!、3!、5!、7!的值

For I = 1 To 7 Step 2

n = 1

For j = 1 To I

n = n * j

Next j

Print n

Next I

For I = 1 To 7 Step 2

For j = 1 To I

n = 1

n = n * j

Next j

Print n

Next I

n = 1

For j = 1 To 7 Step 2

n = n * j

Print n

Next j

n = 1 : j = 1

Do While j <= 7

n = n * j

Print n

j = j + 2

Loop

2 写出下列程序的输出结果

Option Base 1

Private Command1_Click ( )

Dim a(10), p(3) As Integer

k = 5

For I = 1 To 10

a(I) = I

Next I

For I = 1 To 3

p(I) = a(I * I)

Next I

For I = 1 To 3

k = k + p(i) * 2

Next I

Print k

End Sub

3 程序设计:程序的功能是求正整数n的各个位上的数字之和s

Private Sub Form_Click ( )

Dim n%, s%

End Sub

4 设有定义:Dim x%, y% 则以下语句的功能是什么?

x = x + y : y = x – y : x = x - y

5 阅读程序:

Private Sub Command1_Click ( )

x = 0

Do While x <> -1

a = InputBox(“请输入A的值”)

a = Val(a)

b = InputBox(“请输入B的值”)

b = Val(b)

x = InputBox(“请输入X的值”)

x = Val(x)

a = a + b + x

Loop

Print “a = ”; a

End Sub

设在输入对话框中依次输入5、4、3、

2、1、-1,则输出结果是什么?

6 下列程序的运行结果是什么?

Private Sub Form_Click ( )

For I = 1 To 3

For j = 1 To I

For k = j To 3

a = a + 1

Next k

Next j

Next I

Print “a =”, a

End Sub

7 程序填空:猴子吃桃子。当天吃掉一半多一个,第二天接着吃掉剩下的桃子的一半多一个;以后每天都吃剩下桃子的一半多一个,到第10天早上要吃时只剩下了一个,问猴子共摘了多少桃子?

Private Sub Command1_Click ()

Dim n%, I%

X = 1

For I = 10 To 1 Step –1

Next I

Print “共有”; x; “个桃子”

End Sub

因篇幅问题不能全部显示,请点此查看更多更全内容