1、1、求 100 以内的素数。Private Sub Form_Click()Dim i%, j%For i = 2 To 100For j = 2 To i - 1If i Mod j = 0 Then Exit ForNext jIf j = i Then Print iNext iEnd Sub2、从键盘输入任意长度的字符串,要求将字符顺序倒置,例如,将输入的“ABCDEFG”变换成“GFEDCBA” 。Private Sub Command1_Click()Dim a$, I%, c$, d$, n%a = InputBox$(“输入字符串“)n = Len(a)For I = 1 To
2、 Int(n 2)c = Mid(a, I, 1)Mid(a, I, 1) = Mid(a, n - I + 1, 1)Mid (a, n - I + 1, 1) = cNext IPrint aEnd Sub3、计算 0200 之间所有能被 11 或 5 整除的数之和Private Sub Form_Click()Dim n%, i%n = 0For i = 1 To 200If i Mod 11 = 0 Or i Mod 5 = 0 Thenn = n + iEnd IfNext iPrint nEnd Sub4、输入一年份,判断它是否为闰年,并显示有关信息。(判断闰年的条件是:年份能被
3、4整除但不能被 100 整除,或者能被 400 整除)Private Sub Command1_Click()Dim y%y = InputBox(“请输入年数“)If y Mod 4 = 0 And y Mod 100 = Max Then s0 = a(0, j): b0 = jIf a(1, j) = Max Then s1 = a(1, j): b1 = jIf a(2, j) = Max Then s2 = a(2, j): b2 = jIf a(3, j) = Max Then s3 = a(3, j): b3 = jNext jNext iPrintPrint “ 第一行“; s
4、0; “(“; 0; b0; “)“Print “ 第二行“; s1; “(“; 1; b1; “)“Print “ 第三行“; s2; “(“; 2; b2; “)“Print “ 第四行“; s3; “(“; 3; b3; “)“End Sub17、利用随机函数生成一个 44 的矩阵(即二维矩阵),范围是40,80 内的整数,求它的最大值及所对应的下标。Private Sub Form_Click()Dim a%(3, 3)Min = 80For i = 0 To 3For j = 0 To 3a(i, j) = Int(Rnd * 41 + 40)Print Tab(j * 5); a(
5、i, j);If a(i, j) amax Then amax = a(i)If a(i) a(1) Thenmaxa = a(i): m = iEnd IfNext iFor i = 1 To 10Print a(i);Next iPrint “maxa=“ “下标为“ Next jNext iPicture1.PrintFor i = 0 To 3For j = 0 To 3b(i, j) = Int(Rnd * 101 + 100)Picture1.Print b(i, j);Next jNext iPicture1.PrintFor i = 0 To 3For j = 0 To 3c(
6、i, j) = a(i, j) + b(i, j)Next jNext iEnd Sub26、利用随机函数生成一个 44 的矩阵(即二维矩阵), 范围是20,50 内的整数,求它的两条对角线上元素之和。Private Sub Form_Click()Dim a%(3, 3)For i = 0 To 3For j = 0 To 3a(i, j) = Int(Rnd * 31 + 20)Print Tab(j * 5); a(i, j);Next jNext is = a(1, 1) + a(2, 2) + a(3, 3) + a(0, 0) + a(0, 3) + a(1, 2) + a(2, 1) + a(3, 0)PrintPrint “两对角线上元素之和为 :“; sEnd Sub27、利用随机函数生成一个 44 的矩阵(即二维矩阵), 范围是40,80 内的整数,求它的最小值及所对应的下标。Private Sub Form_Click()Dim a%(3, 3)Min = 80For i = 0 To 3For j = 0 To 3a(i, j) = Int(Rnd * 41 + 40)Print Tab(j * 5); a(i, j);