How to find prime number between 1 to n


class Program
{
static void Main(string[] args)
{
//int n = 100000;
int n = 0;
Console.WriteLine(“Type an integer number to get prime number between 1 to n”);
Int32.TryParse(Console.ReadLine(), out n);
PrintPrimes(n);
}

public static void PrintPrimes(int n)
{
bool isPrime = false;
for (int i = 2; i < n; i++) { isPrime = true; for (int j = 2; j <= Math.Sqrt(i); j++) { if (i % j == 0) { isPrime = false; break; } } if (isPrime) Console.Write(i + ” “); } Console.ReadKey(); } } [/csharp] [wpdm_file id=51]

Please share, if it is helpfulShare on FacebookShare on LinkedInTweet about this on TwitterShare on Google+Email this to someonePrint this page

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>