注:例1和例3兩個(gè)中選擇一個(gè)講!
Private Sub Form_click()
Dim x() As Integer, n As Integer
Dim n1 As Integer, n2 As Integer, n3 As Integer
n = 1
Do
ReDim Preserve x(n)
x(i) = InputBox("請(qǐng)輸入一個(gè)數(shù)")
Print x(i);
If x(i) = -999 Then Exit Do
If x(i) < 0 Then
n1 = n1 + 1
ElseIf x(i) = 0 Then
n2 = n2 + 1
Else
n3 = n3 + 1
End If
n = n + 1
Loop
Print "小于0的數(shù)據(jù)個(gè)數(shù)為:"; n1
Print "等于0的數(shù)據(jù)個(gè)數(shù)為:"; n2
Print "大于0的數(shù)據(jù)個(gè)數(shù)為:"; n3
End Sub
例2:打印下面的圖形:----------------------------- 選講內(nèi)容
*********
********
*******
******
*****
****
***
**
*
*
**
***
****
*****
*
***
*****
*******
Private Sub Form_click()
Dim i As Integer, j As Integer
For i = 1 To 9
Print Tab(5);
For j = 1 To 10 - i
Print "*";
Next j
Next i
End Sub
Private Sub Form_click()
Dim i As Integer, j As Integer
For i = 1 To 5
Print Tab(5);
For j = 1 To i
Print "*";
Next j
Next i
End Sub
Private Sub Form_click()
Dim i As Integer, j As Integer
For i = 1 To 4
Print Tab(9 - i);
For j = 1 To 2 * i - 1
Print "*";
Next j
Next i
End Sub
例3 從鍵盤輸入任意個(gè)數(shù),求出這些數(shù)的總和和平均值!
Dim a() as integer
Dim I as integer, sum as integer, avg as single, t as integer
Do
I=inputbox("請(qǐng)輸入一數(shù)!")
If i=-1 then
Exit do
Else
T=t+1
Redim preserve a(t)
A(t)=i
Sum=sum+i
endif
Loop
Avg=sum/ubound(a)
Print "sum=";sum,"avg="+cstr(avg)
例4 編程實(shí)現(xiàn)隨機(jī)生成20個(gè)互不相同的兩位整數(shù)!
Dim a() as integer ,I as integer, n as integer,j as integer
Redim a(20) as integer
For i=1 to 20
k= inputbox("請(qǐng)輸入N的值")
for j=1 to i-1
if a(j)=k then exit for
next j
if j>i-1 then
a(i)=k
else
i=i-1
endif
next i
例 5 在一組有序數(shù)列中插入一個(gè)數(shù),要求插入后的數(shù)還是有序數(shù)列!
Dim a() as integer
Dim I as integer , n as integer, k as integer
For i=1 to 10
A(i)=10*i
Next i
N=inputboxa("請(qǐng)輸入要插入的數(shù)")
以下有兩種方案1 前插入 2 后插入(可以用班級(jí)中的同學(xué)進(jìn)行示范教學(xué))
T=10
Redim preserve a(11)
Do while n
A(t+1)=a(t) T=t-1 Loop A(t+1)=n For i=1 to 11 Print a(i); Next i 后插入法給學(xué)生講清算法的原理,要求學(xué)生自己課后寫出程代碼! 相關(guān)推薦: 2012年下半年計(jì)算機(jī)等級(jí)考試報(bào)名時(shí)間及入口匯總
北京 | 天津 | 上海 | 江蘇 | 山東 |
安徽 | 浙江 | 江西 | 福建 | 深圳 |
廣東 | 河北 | 湖南 | 廣西 | 河南 |
海南 | 湖北 | 四川 | 重慶 | 云南 |
貴州 | 西藏 | 新疆 | 陜西 | 山西 |
寧夏 | 甘肅 | 青海 | 遼寧 | 吉林 |
黑龍江 | 內(nèi)蒙古 |