《VB程序改错.docx》由会员分享,可在线阅读,更多相关《VB程序改错.docx(4页珍藏版)》请在三一办公上搜索。
1、VB程序改错程序改错题 第一题: 题目:以下程序段用于输出100-300的所有素数 - Option Explicit Private Sub Form_Click Dim n As Integer, k As Integer, i As Integer, swit As Integer For n = 101 To 300 Step 2 k = Int(Sqr(n) i = 2 *ERROR* swit = 1 *ERROR* While swit = 0 If n Mod i = 0 Then swit = 1 Else *ERROR* i = i - 1 End If Wend If s
2、wit = 0 Then Print n; End If Next n End Sub 答案 swit=0 While i=i And swit=0 While swit=0 And i=i i=i+1 第二题: 题目:下面程序可输出如下图形: * * * * * - Option Explicit Private Sub Form_Click Dim m As Integer, n As Integer, s As String, i As Integer, j As Integer n = 4 m = 1 s = * For i = 5 To 1 Step -1 *ERROR* Print
3、 Spc(n) For j = 1 To 2 * m - 1 Print s; Next j Print *ERROR* n = n + 1 *ERROR* m = m - 1 Next i End Sub Print Spc(n); Print Spc(i); ?Spc(n); ?Spc(i) n=n-1 n=-1+n m=m+1 第三题: 题目:以下程序段用于计算5的N次方。 - Option Explicit Private Sub Form_Click Dim n As Integer, k As Integer, s As Long n = InputBox( Input n ) *ERROR* k = 0 *ERROR* s = 0 Do While k 3000 Print 从1 到:; i; 的和是; s End Sub 答案 s=0 i=i+1 Loop until s3000 loop Until 3000 s