劳烦各位大侠一分钟。。。帮我编两道题。。

来源:百度知道 编辑:UC知道 时间:2024/05/27 06:09:54
1.从键盘输入一个数M,编程求出2到M的所有素数
2.输入一个数M,求2到M中的完全数(因数之和等于它本身的数,如28=1+2+4+7+14)
不知道,那个是叫VB语言么?就是Dim什么什么if什么什么then...print...
我是电脑盲。。。又不幸碰这些东西。。。唉。。。

楼上的全注意了,正确答案来了,分数我要了
此代码只需添加两个 command按钮到窗体既可

Private Sub Command1_Click() '求素数
Form1.AutoRedraw = True
Dim a, b As Integer
Dim n As Integer
n = InputBox("请输入一个正整数")
For a = 3 To n
b = 2
Do Until a Mod b = 0
b = b + 1
If b = a Then
Print a & " 是素数"
Exit Do
End If
Loop
Next a
End Sub

Private Sub Command2_Click() '求完全数
Form1.AutoRedraw = True
Dim a, b, c, n As Integer
Dim n As Integer
n = InputBox("请输入一个正整数")
For a = 2 To n
c = 0
For b = 1 To a - 1
If a Mod b = 0 Then
c = c + b
End If
Next
If a = c Then
Print a & " 是完全数"
End If
Next
En