1、用VBA程序编程求100到1000间的所有素数,要求每行输出10个素数,最后以对话框的形式输出素数的个数

2 、用VBA编程输出下面几何图案。 666666 55555 4444 333 22 1
2024-10-28 07:49:57
推荐回答(2个)
回答1:

第一题
Sub PRG()
Dim S_COUNT, RC_NO, CR, CC As Integer
RC_NO = 1
For i = 100 To 1000 Step 1
S_COUNT = 0
For j = 1 To i Step 1
If i / j = Int(i / j) Then
S_COUNT = S_COUNT + 1
End If
Next j
If S_COUNT = 2 Then
CR = Int((RC_NO - 1) / 10) + 1
If RC_NO Mod 10 = 0 Then
CC = 10
Else
CC = RC_NO Mod 10
End If
Sheet1.Cells(CR, CC) = i
RC_NO = RC_NO + 1
End If
Next i
MsgBox ("Ò»¹²ÓÐ" & (RC_NO - 1) & "¸öËØÊý")
End Sub

第二题
Sub draw()
For i = 6 To 1 Step -1
Sheet1.Cells(7 - i, 1) = String(i, Chr(Asc(i)))
Next i
End Sub

回答2: