Skip to content

Instantly share code, notes, and snippets.

@seclerp
Created April 8, 2018 17:51
Show Gist options
  • Save seclerp/41d3869dec4dbe2c4715d9b8e50665d7 to your computer and use it in GitHub Desktop.
Save seclerp/41d3869dec4dbe2c4715d9b8e50665d7 to your computer and use it in GitHub Desktop.
Prime nubmer generator
using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
for (int i = 0; i < 10; i++)
{
Console.Write(Prime(i) + " ");
}
}
static int Prime(int n)
{
int result = 2;
for (int i=0; i<n; i++)
{
for (int j=result + 1; j < int.MaxValue; j++)
{
bool isPrime = true;
for (int k=2; k < j; k++)
{
if (j % k == 0)
{
isPrime = false;
}
}
if (isPrime)
{
result = j;
break;
}
}
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment