using System;
using System.Linq;
public class Program
{
public static void Main()
//in this exercise you need to display the first 500 prime numbers (starting at 1) in the output window
//declare variables
// one variable is needed for a counter
// one variable is needed to keep track of the number of prime numbers found
int i = 1;
int intPrimesFound = 0;
//write a while loop that outputs the first 50 prime numbers using Console.WriteLine(string) to output them
// within the loop you can use the IsPrime method which is provided and returns True or False
// example: IsPrime(7)
// tip - your loop will contain an if statement that checkes if the counter is prime
while (intPrimesFound < 500)
if (IsPrime(i))
Console.WriteLine(i);
intPrimesFound++;
}
i++;
//Method writtenf for you to determine if a number is prime
// returns true or false and can be called like: IsPrime(7);
static bool IsPrime(int n)
if (n > 1)
return Enumerable.Range(1, n).Where(x => n%x == 0)
.SequenceEqual(new[] {1, n});
return false;