Prime number Generation

The code sample is a VB.NET program that implements a brute force technique to generate all prime numbers between 1 to 50.

The algorithm , for every number between 1 and 50, checks if the number has any other factor other than 1 and itself. If there exists one such factor, the number is deemed not-prime. Only prime numbers are printed by this program.




Module Module1

Sub Main()
Dim n As Integer
Dim i As Integer
Dim flag As Boolean
For n = 1 To 50
flag = True
For i = 2 To n / 2
If n Mod i = 0 Then
flag = False
End If
Next
If flag Then
Console.WriteLine(n)
End If
Next
Console.ReadLine()
End Sub

End Module



Comments

Author: Raj Kumar Prajapati27 Aug 2008 Member Level: Bronze   Points : 0

ITS WORKING
THANKS SHARE WITH US
RAJ PRAJAPATI

Author: Dharmaraj Nagarajan28 Aug 2008 Member Level: Gold   Points : 0

Hi,
You are welcome.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: