找数求和

来源:百度知道 编辑:UC知道 时间:2024/05/09 09:48:29
找出各位上数字之和为8,并且是素数的所有的两位正整数的和,并输出这些数及其和。
要VB代码、按照给的流程图编写。
如果有错,请指出。谢谢。
急~
点图片,看原图。
代码、VB。 https://gss0.baidu.com/7LsWdDW5_xN3otqbppnN2DJv/%CF%C4%91%5E%D8%BC/pic/item/93a3bc0639ac92ec7a894764.jpeg

答案补充:按照流程图,代码如下。
Option Explicit
Function IsPrime(ByVal n As Long) As Boolean
Dim i As Long
For i = 2 To Int(n / 2)
If n Mod i = 0 Then IsPrime = False: Exit Function
Next
IsPrime = True
End Function

Private Sub Command1_Click()
Dim x As Integer, y As Integer, z As Integer, a As Integer, n As Integer
n = 1
lbl1:
x = 10 * n
y = 8 - n
z = x + y
n = n + 1
If IsPrime(z) Then
Print z
a = a + z
If n >= 8 Then
Print a
Exit Sub
Else
GoTo lbl1
End If
Else
If n = 8 Then
Exit Sub
Else
GoTo lbl1
End If
End If
End Sub
======================
首次回答:
图目前还看不见,我按照我的想法写了。建Command1,代码如下。
====================
Option Explicit

Function IsPrime(ByVal n As Long) As Boolean
Dim i As Long
For i = 2 To Int(n / 2)