我知道一切都是非常错误的。我要做的是创建一个Prime数列表,包括给定的数字。请尽量解释一下。我是新手。非常感谢帮助!
Option Explicit On
Option Strict On
'Author: Murray Spears
'Date: October 5th 2012
'Creating a Program that will ask the user for a number.
'The program will then generate prime numbers up to and including the number entered by the user.
Imports System
Module PrimeNumbers
Sub Main()
Dim Number As Integer
Dim One As Integer = 1
Dim Prime As Boolean
'Ask the user for their chosen number.
Console.Writeline("Choose a number:")
Number = Convert.ToInt32(Console.Readline())
' We have to let the program know that we only want numbers that are divisible by one and themselves, up to the entered value.
Do While Number <= Number
Loop
Do While Number / One = Number
Loop
Do While Number / Prime = Number
Loop
Console.Out.Writeline("Here are the prime numbers:")
Console.Out.Writeline(Number)
End Sub
End Module
答案 0 :(得分:0)
此
Do While Number <= Number
Loop
是一个无限循环,因为Number <= Number
总是为真。
一般提示:停止编码。拿一张纸,尝试写下你想要使用的算法(用简单的英文),即你希望计算机采取的步骤。这样做,直到你确信这会给你想要的结果。
完成算法后,尝试在代码中实现它。如果您遇到问题,请回到这里,发布您的算法并解释实施它时遇到的问题。