vb 编程3到1000之间最大的五个素数之和
Private Sub Command1_Click() s = 0: c = 0 For i = 1000 To 3 Step -1 n = 0 For j = 2 To i - 1 If i Mod j = 0 Then n = n + 1 Next j If n = 0 Then s = s + 1 ElseIf s <= 5 Then c = c + s End If Next i End Sub 这个方法中 哪里错了
答案为4919, 五个素数是:997,991,983,977,971 =============================================== Dim s As Integer Dim c As Integer, i As Integer, j As Integer Dim y As Boolean '素数标志 Private Sub Command1_Click() s = 0: c = 0: y = False For i = 999 To 3 Step -2 '偶数不用检查 y = True For j = 2 To (i / 2) '只需检查到i/2 If i Mod j = 0 Then '非素数 Debug。
Print i, j '提示这个非素数的最小因子 y = False Exit For End If Next j If y Then s = s + 1 c = c + i Debug。
Print "i="; i, "s="; s, "c="; c End If If s = 5 Then MsgBox "最大5个素数之和=" &c Exit For End If Next i End Sub。
Private Sub Command1_Click() s = 0: c = 0 For i = 1000 To 3 Step -1 n = 0 For j = 2 To i - 1 If i Mod j = 0 Then n = n + 1 Next j If n = 0 Then s = s + 1 end if If s <= 5 Then c = c + i End If Next i End Sub for循环的效率比较低,建议使用Loop,大幅缩短运行时间!
答:产生一个四位数,从千位到个位依次是1,2,3,4 如果把括号里的四个数换了,比如5,8,7,9 那产生的四位数就是5879(五千八百七十九) 先定义一个集合a,...详情>>
答:线性链表分好几种,分为单链,双链等,它们的存储顺序也不一样. 线性表是顺序存储的,占顺序的存储空间详情>>
问:电脑安装了VB6.0,为什么打开方式里面没有VB程序选项,进安装好的VB里去关联...
答:打开方式最下面还有一个《选择程序》,点开后查VB的安装目录的EXE,找到后直接打开,下次就会在打开方式里查到了详情>>