78 452
Assignments Done
Successfully Done
In September 2019

Answer to Question #19887 in Visual Basic for Annie

Question #19887
write to program to input that the ending no from the user and display all the prime no according to this number
Expert's answer
Module Module1

Sub Main()
Dim n As Integer = 0
Console.Write("Please enter a number larger than two: ")
n = Integer.Parse(Console.ReadLine())
For i As Integer = 2 To n
Dim prime As Boolean = IsPrime(i)
If prime Then
Console.Write(i.ToString() + " Prime" + Environment.NewLine())
End If

Console.Write("Press any key to exit...")
End Sub
Private Function IsPrime(ByVal number As Integer) As Boolean
If ((number And 1) = 0) Then
If (number = 2) Then
Return True
Return False
End If
End If

For i As Integer = 3 To number Step 2
i *= i
If ((number Mod i) = 0) Then
Return False
End If
Return number <> 1
End Function

End Module

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions