prince all prime numbers within the range of 1 to 100 in csharp
main.cs
using System;
classProgram{
staticvoidMain(string[] args) {
// initialize array with all values set to truebool[] primes = newbool[101];
for (int i = 0; i < primes.Length; i++)
{
primes[i] = true;
}
// loop through array and mark non-prime numbers as falsefor (int i = 2; i <= Math.Sqrt(100); i++)
{
if (primes[i])
{
for (int j = i * i; j <= 100; j += i)
{
primes[j] = false;
}
}
}
// print out all prime numbers in the range of 1 to 100for (int i = 2; i <= 100; i++)
{
if (primes[i])
{
Console.Write(i + " ");
}
}
}
}