Created
April 8, 2018 17:51
-
-
Save seclerp/41d3869dec4dbe2c4715d9b8e50665d7 to your computer and use it in GitHub Desktop.
Prime nubmer generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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