[其它]VB程序改錯40題_第1頁
[其它]VB程序改錯40題_第2頁
[其它]VB程序改錯40題_第3頁
[其它]VB程序改錯40題_第4頁
[其它]VB程序改錯40題_第5頁
已閱讀5頁,還剩42頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、第2題 (1.0分) 題號:129-【程序改錯】-題目:該程序?qū)崿F(xiàn)將輸入的 0 - 255 之間的正整數(shù)轉(zhuǎn) 換成二進(jìn)制數(shù)-option explicitprivate sub form_click() const n = 8 dim a(n) as integer, s as string, m as integer, x as integer x = val(inputbox(請輸入一個 0 - 255 之間的正整數(shù):) print x*found* for m = 1 to n a(m) = x mod 2*found* x = x / 2 next m s = for m = n to

2、0 step -1*found* s = str(a(m) next m print s end sub答案:=(答案1)=for m = 0 to n=(答案2)=x= x 2=或=x= int(x/2)=(答案3)=s = s + str(a(m)第3題 (1.0分) 題號:463-【程序改錯】-題目:以下程序功能是輸入三個數(shù),由大到小排序。-option explicitdim a as integerdim b as integerdim c as integerprivate sub form_click() dim ntemp as integer a = val(inputbox

3、(please input first integer, 輸入正整數(shù)) b = val(inputbox(please input second integer, 輸入正整數(shù)) c = val(inputbox(please input third integer, 輸入正整數(shù)) *found* if a = c then ntemp = a a = b b = ntemp end if *found* if b = c then ntemp = a a = c c = ntemp end if *found* if a = b then ntemp = b b = c c = ntemp e

4、nd if print the integers in order is; a; b; cend sub答案:=(答案1)=if a = a then=(答案2)=if a = a then=(答案3)=if b = b then第4題 (1.0分) 題號:127-【程序改錯】-題目:下面程序可輸出如下圖形: * * * * *-option explicitprivate sub form_click()dim m as integer, n as integer, s as string, i as integer, j as integern = 4m = 1s = *for i = 5

5、 to 1 step -1 *found* print spc(n) for j = 1 to 2 * m - 1 print s; next j print *found* n = n + 1 *found* m = m - 1next iend sub答案:=(答案1)=print spc(n);=或=print spc(i);=或=? spc(n);=或=? spc(i);=(答案2)=n = n - 1=或=n = - 1+n=(答案3)=m = m + 1第5題 (1.0分) 題號:469-【程序改錯】-題目:已知一個函數(shù)f(x)=1000*sin(x),利用繪圖方法 在圖片框中顯示

6、其圖形。結(jié)果如圖1-option explicitprivate const pi = 3.14159private sub command1_click() *found* dim x as integer picture1.scale (-pi, -1200)-(pi, 1200) *found* for x = -pi to pi step pi *found* picture1.pset (x, 1000 * pi * sin(x), vbred next xend sub答案:=(答案1)=dim x as single=或=dim x!=(答案2)=for x = -pi to p

7、i step pi / 180=(答案3)=picture1.pset (x, 1000 * sin(x), vbred=或=picture1.pset (x, sin(x)*1000), vbred第6題 (1.0分) 題號:497-【程序改錯】-題目:編程求一個十進(jìn)制整數(shù)n的各位數(shù)字之和,設(shè)n為小于或等于5位的數(shù)。-option explicitprivate sub form_click() dim n as integer, sum as integer, s1 as string, s2 as string dim i as integer, ch as string sum = 0

8、 n = inputbox(輸入整數(shù)n) s1 = str(n) *found* s1 = rtrim(s1) for i = 1 to len(s1) *found* ch = mid(n, i, 1) *found* sum = val(ch) next i print 該整數(shù)的各位數(shù)之和是:; sumend sub答案:=(答案1)=s1 = trim(s1)=或=s1 = ltrim(s1)=(答案2)=ch = mid(s1, i, 1)=(答案3)=sum = sum + val(ch)=或=sum = sum + val(ch)第7題 (1.0分) 題號:454-【程序改錯】-題

9、目:本程序的功能是隨機(jī)產(chǎn)生的10個兩位正整數(shù),并進(jìn)行遞減排序。-option explicitprivate sub creaternd() dim temp as integer dim i as integer dim n as integer dim x(10) as integer dim j as integer n = 10 print 數(shù)據(jù): for i = 1 to n *found* x(i) = int(rnd() * 90) print x(i); next i print print 排序: for i = 0 to n - 1 for j = i + 1 to n *

10、found* if x(i) x(j) then *found* temp = x(i) x(j) = x(i) x(i) = temp end if next j print x(i); next i printend subprivate sub command1_click() createrndend sub答案:=(答案1)=x(i) = int(10 + rnd() * 90)=或=x(i) = int(10 + rnd() * 90)=(答案2)=if x(i) x(j) then=或=if x(i) x(i) then=或=if x(j) = x(i) then=(答案3)=t

11、emp = x(j)第9題 (1.0分) 題號:130-【程序改錯】-題目:以下程序段用于計算5的n次方。-option explicitprivate sub form_click() dim n as integer, k as integer, s as long n = inputbox( input n )*found* k = 0*found* s = 0 do while k = n s = s * 5 k = k + 1*found* next print 5的; n次方是; send sub答案:=(答案1)=k=1=(答案2)=s=1=(答案3)=loop第11題 (1.0

12、分) 題號:452-【程序改錯】-題目:用自定義函數(shù)的方法求sum(x),求當(dāng)-1x1時, sum(x)=x/2!+x2/3!+x3/4!+xn/(n+1)!, 當(dāng)x1或x-1時,函數(shù)值為0。當(dāng)n=0時,輸入數(shù) 據(jù)錯誤。x、n都是由用戶輸入。-option explicitprivate sub command1_click() dim s as single dim n as integer, x as single, k as integer n = val(inputbox(please input a integer value:) x = val(inputbox(please in

13、put a single value:) if n 1 or x 0 then pjf = pjf / 30 debug.print 不及格 + str$(bjg) + 人,及格 + str$(jg) + 人,中等 + str$(zd) + 人; debug.print 良好 + str$(lh) + 優(yōu)秀 + str$(yx) + 人 debug.print 優(yōu)秀分?jǐn)?shù)段成績平均分 & pjfend sub答案:=(答案1)=a = int( rnd() * 100)=或=a = int( rnd * 100)=(答案2)=pjf = pjf + a=(答案3)=if yx 0 then pj

14、f = pjf / yx第17題 (1.0分) 題號:456-【程序改錯】-題目:挑選單數(shù)并排序程序:程序啟動后由計算機(jī)自動產(chǎn) 生20個屬于100,300之間的隨機(jī)整數(shù),單擊顯 示全體按鈕時,在form1上顯示這20個隨機(jī)數(shù); 單擊顯示奇數(shù)按鈕時,在form1上顯示其中的奇數(shù); 單擊排序按鈕時,在form1上將這些奇數(shù)從小到大顯示。 要求顯示格式為每行顯示5個數(shù)據(jù)。-option explicitprivate a(20) as integer, b(20) as integerprivate k as integerprivate sub cmdodd_click()dim i as int

15、egerk = 0for i = 1 to 20 *found* if a(i) / 2 = int(a(i) / 2) then k = k + 1 b(k) = a(i) end ifnext ifor i = 1 to k print b(i); *found* if int(i / 5) i / 5 then printnext iprintend subprivate sub cmdall_click() randomize dim i as integer for i = 1 to 20 *found* a(i) = int(rnd() * 20 + 100) print a(i)

16、, if int(i / 5) = i / 5 then print next i printend subprivate sub cmdsort_click() dim i as integer dim j as integer dim temp as integer for i = 1 to k - 1 for j = i to k if b(i) b(j) then temp = b(i): b(i) = b(j): b(j) = temp next j next i for i = 1 to k print b(i); if int(i / 5) = i / 5 then print

17、next iend sub答案:=(答案1)=if a(i) / 2 int(a(i) / 2) then=或=if a(i) mod 2 0 then=或=if 0a(i) mod 2 then=或=if a(i) / 2 a(i) 2 then=或=if int(a(i) / 2) a(i) / 2 then=或=if a(i) 2 a(i)/2 then=(答案2)=if int(i / 5) = i / 5 then print=或=if i mod 5 = 0 then print=或=if 0 = i mod 5 then print=或=if i / 5= int(i / 5)

18、then print=或=if i / 5= i 5 then print=或=if i 5= i/ 5 then print=(答案3)=a(i) = int(rnd() * 200 + 100)第19題 (1.0分) 題號:499-【程序改錯】-題目:編程將一個數(shù)從已經(jīng)有序(設(shè)從小到大排序)的數(shù)組 中刪除,使數(shù)組還繼續(xù)保持有序而且其余元素按照下 標(biāo)連續(xù)存放。-option explicitprivate sub form_click() dim a() as integer, n as integer, flag as integer dim i as integer, x as inte

19、ger, p as integer flag = 0 n = inputbox(輸入元素個數(shù)) *found* dim a(n) for i = 1 to n a(i) = inputbox(輸入數(shù)組的第 & i & 個元素) next i print 刪除某元素前的數(shù)組 for i = 1 to n print a(i); next istart: x = inputbox(輸入要刪除的元素:) for i = 1 to n if x = a(i) then p = i: flag = 1 next i if flag = 0 then msgbox (沒有此元素): goto start

20、for i = p to n - 1 *found* a(i + 1) = a(i) next i *found* n = n + 1 print 刪除元素后的數(shù)組: for i = 1 to n print a(i); next iend sub答案:=(答案1)=redim a(n)=(答案2)=a(i) = a(i + 1)=或=a(i) = a(1 + i)=(答案3)=n = n - 1第20題 (1.0分) 題號:139-【程序改錯】-題目:隨機(jī)產(chǎn)生并輸出100以內(nèi)大于50的20個整數(shù),輸 出時每5個數(shù)一行。-option explicitprivate sub form_clic

21、k()randomize timerdim i as integer, ma as integer*found*i = 1*found*do until i 50 then print ma; i = i + 1*found* if i 5 = 0 then print end ifend ifloopend sub答案:=(答案1)=i = 0=(答案2)=do while i i=或=do while i =i=(答案3)=if i mod 5 = 0 then第23題 (1.0分) 題號:474-【程序改錯】-題目:程序功能為求解一元二次方程的實根,請修正程序中錯誤。-option ex

22、plicitprivate sub form_load() dim a!, b!, c!, root1#, root2#, work as double a = val(inputbox( 請輸入系數(shù)a的值) b = val(inputbox( 請輸入系數(shù)b的值) c = val(inputbox( 請輸入系數(shù)c的值) *found* work = b * 2 - 4 * a * c if work = 0 and a 0 then *found* root1 = (sqr(work) / (2 * a) *found* root2 = (sqr(work) / (2 * a) debug.p

23、rint 有二個實根 + str$(root1) + , + str$(root2) else debug.print 無實根! end ifend sub答案:=(答案1)=work = b 2 - 4 * a * c=或=work = b *b - 4 * a * c=(答案2)=root1 = (-b + sqr(work) / (2 * a)=或=root1 = ( sqr(work) -b ) / (2 * a)=或=root1 = (-b + sqr(work) / ( a*2)=或=root1 = ( sqr(work) -b ) / ( a*2)=(答案3)=root2 = (

24、-b - sqr(work) / (2 * a)=或=root2 = (- sqr(work) - b) / (2 * a)=或=root2 = (-b - sqr(work) / ( a*2)=或=root2 = (- sqr(work) - b) / (a*2)第28題 (1.0分) 題號:133-【程序改錯】-題目:下面程序?qū)?0個整數(shù)從大到小排序-option explicitprivate sub form_click()dim t%, m%, n%, w%dim a(10) as integerfor m = 1 to 10 a(m) = int(10 + rnd() * 90)

25、print a(m); ;next mprintfor m = 1 to 9 t = m*found* for n = 2 to 10*found* if a(t) a(n) then n = t next n*found* if t = m then w = a(m) a(m) = a(t) a(t) = w end ifnext mfor m = 1 to 10 print a(m)next mend sub答案:=(答案1)=for n = m + 1 to 10=(答案2)=if a(t) a(t) then t = n=(答案3)=if t m then=或=if not t = m

26、 then=或=if not m = t then第30題 (1.0分) 題號:480-【程序改錯】-題目:下面函數(shù)的功能是:求變量s(s=a+aa+aaa+aaaa+) 的值。其中,a是一個0-9的數(shù)字,總共累加a項。 例如,當(dāng)a=3時,s=3+33+333 (共累加3項)。-option explicitpublic function calc(a as integer) dim s as long dim t as long dim i as integer s = a *found* t = 1 for i = 2 to a *found* t = t + a s = s + t ne

27、xt i calc = s print send functionprivate sub command1_click() dim i as integer i = inputbox(請輸入數(shù)字(0-9):) *found* calc call iend sub答案:=(答案1)=t = a=(答案2)=t = t * 10 + a=或=t = t * 10 + a=或=t = t * 10 + a=(答案3)=calc i=或=call calc(i)=或=calc (i)第31題 (1.0分) 題號:489-【程序改錯】-題目:給定三角形的三條邊,計算三角形的面積。要求 程序首先判斷給定的

28、三條邊能否構(gòu)成三角形。-option explicitprivate sub form_click() dim a as single, b as single, c as single dim s as single, t as singlestart: a = inputbox(輸入1邊長:) b = inputbox(輸入2邊長:) c = inputbox(輸入3邊長:) *found* if a + b c or b + c a then msgbox (不能構(gòu)成三角形,請重新輸入個邊) goto start end if *found* t = (a + b) / 2 *found* s = sqr(t - a) * (t - b) * (t - c) print 該三角形的面積:; send sub答案:=(答案1

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論