八年級信息技術(shù)教案第六章 各就各位---數(shù)組
for i=1 to n
if num=num(i) then
print "num";num(i)
print "name";nam$(i)
exit for
end if
next i
if i>n then num ;"not found"
end sub
• 折半查找法(二分查找法);
對按一定規(guī)律(由小到大或由大到。┡帕泻玫臄(shù)據(jù)進(jìn)行檢索;假設(shè):num(i)為按從小到大排列的學(xué)生學(xué)號,nam$(i)為姓名,num為查找對象。
sub search
top=1
bot=n
find=0
do
mid=int((top+bot)/2)
if num=num(mid) then
print "num";num(i)
print "name";nam$(i)
find=1
elseif num<num(mid) then
bot=mid-1
elseif num>num(mid) then
top=mid+1
end if
loop until ((bot<top) or (find=1))
if find=0 then num ;"not found"
end sub
2、二維數(shù)組
矩陣的表示:
aij——雙下標(biāo)變量 a(i,j)→二維數(shù)組
數(shù)組定義:dim a(m,n)
a(i,j)→b(j,i)
例: 輸出魔陣——每行、每列和對角線之和均相等。
排列規(guī)律:
(1)、先將“1”放在第一行當(dāng)中;
(2)、從“2”開始到n*n止,各數(shù)中每一個數(shù)存放的行比前一個數(shù)的行數(shù)減1,列數(shù)加1;
(3)、如果上一個數(shù)的行數(shù)為1,則下一個數(shù)的行數(shù)為n(最后一行);
(4)、當(dāng)上一個數(shù)的列數(shù)為n時,下一個數(shù)的列數(shù)為1,行數(shù)減1;
(5)、如下一個數(shù)應(yīng)放的位置已被其它數(shù)占據(jù),則下一個數(shù)放在上一個數(shù)的下面。
四、過程中的數(shù)組參數(shù)
1、作為下標(biāo)變量
子程序定義:sub a(x,y)
……
end sub
調(diào)用:dim t(10)
……
call a(t(1),t(2))
2、作為數(shù)組:
定義 :
調(diào)用 call b(p(),g())
將主程序中的p、g傳給子程序中的a,b 數(shù)組傳遞采取“地地傳遞”方式。即子程序中對形象參值的修改,將會改變實參值
教學(xué)后記: