版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、程序填空】1.功能:以下程序段用于實(shí)現(xiàn)矩陣轉(zhuǎn)置,即將一個n x m的矩陣的行和列互換Private Sub Form_Click()Const n = 3Const m = 4Dim a(n, m), b(m, m) As IntegerFor I = 1 To nFor j = 1 To ma(I, j) = Int(Rnd * 90) + 10Next jNext iFor I = 1 To nFor j = 1 To mB(I,j)=a(I,j)Next jNext IPrint 矩陣轉(zhuǎn)置前 For I = 1 To nFor j = 1 To mPrint a(I, j);Next j
2、printNext IPrint 矩陣轉(zhuǎn)置后 For I = 1 To mFor j = 1 To nPrint b(I, j);Next jPrintNext IEnd Sub1. 功能:輸入數(shù)字 1-7,顯示其對應(yīng)是星期幾 (例:輸入 1,顯示星期日 ,如果輸入其它內(nèi)容, 一律顯示 輸入錯誤 )Private Sub Command1_Click()dim x as integerdim y as stringx=val(text1.text)Select case xcase 1 y= 今天是星期日 case 2 y= 星期一 case 3 y= 星期二 case 4 y= 星期三 ca
3、se 5 y= 星期四 case 6 y= 星期五 case 7 y= 星期六 Case elsey = 輸入錯誤 end selectText2.Text = yEnd Sub1. 功能:求 1!+2!+10!的值。Private Sub Form_Click()T=1s = 1For I = 2 To 10 t = t * I S=s+tNext iPrint sEnd Sub1.功能:以下程序段用于計算n的階乘:n! (1! =1)Public Function fac(n As Integer) As IntegerIf n = 1 Thenfac = 1Elsefac = n * f
4、ac(n-1)End IfEnd FunctionPrivate Sub Command1_Click()Print fac(4)=; fac(4)End Sub1. 功能: 以下程序的功能是: 生成 20 個 200 到 300 之間的隨機(jī)整數(shù), 輸出其中能被 5 整除的數(shù)并求出它們的和Private Sub Command1_Click()Dim s As IntegerDim x As Integer, i As Integers = 0For i = 1 To 20RandomizeX = Int(rnd * 100 + 200)If X mod 5 = 0 ThenPrint Xs
5、= s + XEnd IfNext iPrin t Sum = ; sEnd Sub1. 功能:在窗體上畫一個標(biāo)簽(名稱為 Label1 )和一個計時器(名稱為 Timer1 ),然后編寫如下幾個事件過程:要求:每一秒鐘 Label1 更新顯示一次系統(tǒng)時間Private Sub Form_Load()Timer1.Enabled = FalseTimer1.Interval = 1000End SubPrivate Sub Form_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Timer1_Timer()Label1.Caption = Now
6、1.功能:窗體上建立了兩個文本框Text1(輸入字符串)及Text2(轉(zhuǎn)換結(jié)果),一個命令按鈕Command1( 清除 ) 。錄入 Text1 內(nèi)容時,將錄入內(nèi)容大寫字母轉(zhuǎn)為小寫,小寫轉(zhuǎn)為大 寫。Private Sub Command1_Click()Text1.Text = Text2.Text = Text1.SetFocusEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)Dim s As String * 1s = chr(KeyAscii) Select Case s Case A to Z s = LCase(s) Case
7、 a To zs = Ucase(s)Case Else一s = *End SelectText2.Text = Text2.Text + sEnd Sub1. 功能:窗體上建立了一個文本框 Text1 (輸入口令 )和一個命令按鈕 Command1( 檢查 ) 。判斷密碼是否正確,并顯示相應(yīng)提示在加載窗體時設(shè)置密碼框最大長度為8,密碼顯示字符為“ * ”dim x as stringPrivate Sub Command1_Click()x = Text1.TextIf x = 12345678 ThenMsgBox ( 歡迎你用機(jī) !)ElseMsgBox ( 對不起,口令錯 ) End
8、IfText1.Text = Text1.SetFocusEnd SubPrivate Sub Form_Load()Text1.Text = Text1.maxlength = 8Text1.Psswordchar = *1. 功能:下面的程序段用于打印出以下圖形*Private Sub Form_Click() Dim i%, j%, k%For i = 0 To 3For j = 0 To 2 - i Print ;Next jFor k = 1 To 2*i+1Print *;Next kPrintNext iFor i = 0 To 2For j = 0 To iPrint “”;N
9、ext jFor k = 0 To 4 - 2 * iPrint *;Next kprintNext iEnd Sub1.功能:下面的程序段用于求矩陣相乘C=A x B,設(shè)A、B、C分別為m x p、p x n、mx n的矩陣。Private Sub Form_Click()Const m = 4, p = 3, n = 2Dim a(1 To m, 1 To p) As IntegerDim b(1 To p, 1 To n) As IntegerDim c(1 To m, 1 To n) As IntegerDim i As Integer, j As Integer, k As Inte
10、ger, sum As IntegerFor i = 1 To mFor k = 1 To pa(i, k) = iNext kNext iFor i = 1 To pFor k = 1 To nb(i, k) = iNext kNext iFor i = 1 To mFor j = 1 To nSum=0For k = 1 To psum = sum +a(I,k)*b(k,j)Next k c(i, j) =sumNext j, iPrint 輸出矩陣 For i = 1 To mFor k = 1 To nPrint c(i, k),Next kPrintNext iEnd Sub1.
11、功能:利用下面的過程求 m! 和 m*nPrivate Sub Form_Click()Dim m As Integer, n As Integerm = 2 n = 3 Find m,nEnd SubPrivate Sub find(x As Integer, y As Integer)Dim s, i As IntegerS=1For i = 1 To x s = s * i p=x*yNext iPrint s, pEnd Subx 大于 y。1.題目:已知用inputbox函數(shù)輸入兩個數(shù) x和y,比較它們的大小,使得 Private Sub Form_Click()Dim x As S
12、ingle, y As Singlex = InputBox( 輸入數(shù)據(jù) 1 : )y = InputBox( 輸入數(shù)據(jù) 2: )Print x 值, y 值Print x, yIf x y ThenT=xX=yY=tEnd IfPrint x, yEnd Sub程序改錯】1. 題目:以下程序段用于打印如圖 1 所示的九九乘法表:Option ExplicitPrivate Sub Form_Click()Dim i As Integer, j As Integer, k As IntegerPrint Tab(30); 9*9 tablePrint: PrintPrint * ;For i
13、= 1 To 9Print Tab(i * 6); I;Next iPrintFor j = 1 To 9Print j; ;For k = 1 To jPrint Tab(k * 6); j * k; ;Next kPrintNext jEnd Sub1. 題目:求 s=1!+3!+5!+7! ,階乘的計算用 Function 過程 fact 實(shí)現(xiàn) . Option ExplicitPrivate Sub Form_Click()Dim i As Integer, s As IntegerFor i = 1 To 7 step 2s = s + fact(i)Next iPrint sEnd
14、 SubPublic Function fact(ByV al n As Integer)Dim t As Integer, i As Integert = 1For i = 1 To nt = t * iNext ifact =tEnd Function1. 題目 :請根據(jù)下列描述編寫購物優(yōu)惠程序。某商場為了加速促成商品流通,采用購物打 折的優(yōu)惠辦法,每位顧客一次購物(1)在 100 元以上者,按九五折優(yōu)惠; ( 2)在 200元以上者,按九折優(yōu)惠; (3)300 元以上者,按八折優(yōu)惠; ( 4)500元以上者按七折優(yōu) 惠。Option ExplicitPrivate Sub Command
15、1_Click()Dim x As Single, y As Singlex = Val(Text1.Text)If x 100 ThenY=xElseIf x 200 Then y = 0.95 * xElseIf x 300 Theny = 0.9 * xElseIf x a(n) Then t=nNext nIf t m Then w = a(m) a(m) = a(t) a(t) = wEnd IfNext mFor m = 1 To 7Print a(m)Next m End Sub5 個數(shù)一行。1. 題目:輸出 40以內(nèi)能夠被 3 整除的數(shù),要求輸出結(jié)果為 Option Expli
16、citPrivate Sub Form_Click()ClsDim x As IntegerDim i As Integeri = 0For x = 1 To 40If (x / 3) = (x 3) ThenPrint x;i = i + 1End IfIf i Mod 5 = 0 ThenPrintEnd Ifnext iEnd Sub1. 題目 :編程求一個 m*n 矩陣中最大元素及其所在的行列號。Option ExplicitPrivate Sub Form_Click()Dim A() As Integer, max As IntegerDim M As Integer, N As
17、IntegerDim i As Integer, j As IntegerDim col As Integer, row As Integer M = InputBox( 輸入矩陣的行數(shù): ) N = InputBox( 輸入矩陣的列數(shù): )ReDim A(1 To M, 1 To N) As IntegerFor i = 1 To MFor j = 1 To NA(M, N) = InputBox( 輸入數(shù)組元素 :) Next jNext i max = A(1,1)For i = 1 To MFor j = 1 To NIf max 3000Print 從 1 到:; i; 的和是; s
18、 End Sub1. 題目:用輾轉(zhuǎn)相除法求兩個整數(shù)的最大公約數(shù)。Option ExplicitFunction gcd(ByV al m As Integer, ByV al n As Integer) As IntegerDim r As Integer r = m Mod nDo While r 0M=n n = r r = m Mod nLoopgcd = nEnd FunctionPrivate Sub Form_Click()Dim a As Integer, b As Integer, c As Integera = InputBox( 輸入一個整數(shù) )b = InputBox(
19、輸入一個整數(shù) )a = Val(a)b = Val(b)c=gcd(a, b)Print a, b, cEnd Sub1. 題目:密碼判斷程序, 如果密碼為 12345則顯示“恭喜,密碼正確”,否則顯示 “很遺憾, 密碼錯誤”,要求文本框中只允許輸入數(shù)字。Option ExplicitPrivate Sub Command1_Click()Dim strPws As String strPws = Trim(Text1.Text)If Len(strPws) = 0 Then Exit SubIf strPws = 12345 ThenMsgBox 恭喜,密碼正確 , , 驗(yàn)證ElseMsgB
20、ox 很遺憾,密碼錯誤 , , 驗(yàn)證 End IfEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)If Not (KeyAscii = 48 And KeyAscii = 57) Then KeyAscii = 0End IfEnd Sub832 的值。1. 題目:求 s=72+102+132+ Option ExplicitPrivate Sub Form_Click()ClsDim s As LongDim i As Integers = 0For i = 7 To 832 step 30s = s + inext iPrint
21、s End Sub1. 題目:下邊是一個小動畫程序,在窗體上放一個標(biāo)簽 Label1 ,每過 1 秒鐘標(biāo)簽 Label1 的背景顏色由紅到藍(lán), 由藍(lán)到綠,再由綠到紅循環(huán)變化, 并自動修改標(biāo)簽 Label1 的 Left , Top 值使其從左上角沿窗體的對角線移動到窗體的右下角,如此往復(fù)從而實(shí)現(xiàn)動畫。Option ExplicitPrivate flag As IntegerPrivate Sub Form_click()Timer1.Enabled = TrueEnd SubPrivate Sub Form_Load()Timer1.Interval = 1000Label1.Left =
22、0Label1.Top = 0Label1.BackColor = vbBlack Timer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer()If Label1.Left Left + Width And Label1.Top = Top + Height ThenLabel1.Left = Label1.Left + 100 * Width / HeightLabel1.Top = Label1.Top + 100ElseLabel1.Left = LeftLabel1.Top = TopEnd IfIf flag = 0 ThenLabe
23、l1.BackColor = vbBlueflag = 1ElseIf flag = 1 ThenLabel1.BackColor = vbGreenflag = 2ElseLabel1.BackColor = vbRedflag = 0End IfEnd Sub程序設(shè)計】1.題目: (事件 )單擊窗體。 (響應(yīng) )求 200300 之間既能被 3 整除又能被 7 整除的數(shù)。并求出所有數(shù)之和存入變量 SUM 中Private Sub Form_Click()Dim sum As Integersum = 0Dim i As IntegerFor i = 201 To 300If (i Mod 3) = 0) And (i Mod 7) = 0) ThenPrint (CStr(i)sum = sum + iEnd IfNextPrint sumYZJ (sum)End SubPrivate Sub YZJ(i As Inte
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 關(guān)于撫養(yǎng)權(quán)的離婚協(xié)議
- 2.3《林黛玉進(jìn)賈府》【中職專用】高一語文(高教版2023基礎(chǔ)模塊上冊)
- 湖南省郴州市第六中學(xué)觀山學(xué)校2023-2024學(xué)年七年級上學(xué)期第三次月考生物試題(原卷版)-A4
- 2023年地震數(shù)據(jù)采集系統(tǒng)項目籌資方案
- PEP人教版小學(xué)六年級上冊Unit6 How do you feel B Lets try Lets talk
- 《知識與個人知識》課件
- 電工(初級工)測試題及參考答案
- 山東省濟(jì)寧市微山縣2023-2024學(xué)年八年級上學(xué)期期末考試數(shù)學(xué)試卷(含答案)
- 養(yǎng)老院老人入住資料制度
- 養(yǎng)老院老人安全管理制度
- 2024年人教版初一生物(上冊)期末試卷及答案(各版本)
- 2024年秋新北師大版七年級上冊數(shù)學(xué)教學(xué)課件 第六章 3 數(shù)據(jù)的表示 第3課時 統(tǒng)計圖的選擇
- 胰島素注射操作并發(fā)癥的預(yù)防及處理
- 人教新目標(biāo)版英語七下Unit 11《How was your school trip》(Section A 1a-1c)教學(xué)設(shè)計
- (新版)管道工(初級)職業(yè)鑒定考試題庫(含答案)
- 大話機(jī)器人智慧樹知到期末考試答案章節(jié)答案2024年青海大學(xué)
- 含新能源發(fā)電接入的電力系統(tǒng)低頻振蕩阻尼控制研究綜述
- 2024年全國甲卷高考數(shù)學(xué)(理數(shù))真題試題(原卷版+含解析)
- 電大建筑材料(A)歷年試題和答案(精)請勿轉(zhuǎn)載
- 貴州省遵義市播州區(qū)2023-2024學(xué)年八年級上學(xué)期期末學(xué)業(yè)水平監(jiān)測數(shù)學(xué)試卷(含解析)
- 實(shí)驗(yàn)室生物安全試題及參考答案
評論
0/150
提交評論