Small update to prime numbers app
Data is now saved to a list to save on system performance. The list is printed out once all of the prime numbers up to the limit have been discovered.
This commit is contained in:
parent
5692e8dae3
commit
95c5fe0e23
@ -13,6 +13,7 @@ namespace Prime_Numbers__Efficient_
|
||||
int startNum = 2;
|
||||
int maxNum = Convert.ToInt32(Console.ReadLine());
|
||||
bool isPrime = true;
|
||||
List<int> primeList = new List<int>();
|
||||
|
||||
for (int x = startNum; x <= maxNum; x++)
|
||||
{
|
||||
@ -26,18 +27,20 @@ namespace Prime_Numbers__Efficient_
|
||||
}
|
||||
if (isPrime == true)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine(x);
|
||||
primeList.Add(x);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(x);
|
||||
isPrime = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach (var item in primeList)
|
||||
{
|
||||
Console.WriteLine(item);
|
||||
}
|
||||
|
||||
Console.ReadLine();
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user