C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Prime number Generation


Posted Date: 24 Feb 2008    Resource Type: Code Snippets    Category: Mathematics

Posted By: Dharmaraj       Member Level: Diamond
Rating:     Points: 5



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






Responses

Author: Raj Kumar Prajapati    27 Aug 2008Member Level: Bronze   Points : 0
ITS WORKING
THANKS SHARE WITH US
RAJ PRAJAPATI


Author: Dharmaraj    28 Aug 2008Member Level: Diamond   Points : 0
Hi,
You are welcome.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Prime number generation  .  Generate prime numbers in a range  .  Generate prime numbers  .  All prime numbers within 50  .  All prime numbers in a range  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Swapping integer values [Using XOR - Advanced method]
Previous Resource: Buble sorter
Return to Discussion Resource Index
Post New Resource
Category: Mathematics


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

conference call definitions

Contact Us    Privacy Policy    Terms Of Use