0

我知道一切都非常错误。我想要做的是创建一个素数列表,包括给定的数字。请尽量简单解释。我是新手。非常感谢您的帮助!

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
4

1 回答 1

0

这个

Do While Number <= Number
Loop

是一个无限循环,因为Number <= Number总是正确的。

一般提示:停止编码。拿一张纸,试着写下你想使用的算法(用简单的英语),即你希望计算机采取的步骤。这样做,直到你确信这会给你想要的结果。

一旦你制定了你的算法,试着在代码中实现它。如果您对此有疑问,请返回此处,发布您的算法并解释您在实现它时遇到的问题。

于 2012-10-10T14:43:50.900 回答