prince all prime numbers within the range of 1 to 100 in csharp

main.cs
using System;

class Program
{
    static void Main(string[] args)
    {
        // initialize array with all values set to true
        bool[] primes = new bool[101];
        for (int i = 0; i < primes.Length; i++)
        {
            primes[i] = true;
        }

        // loop through array and mark non-prime numbers as false
        for (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 100
        for (int i = 2; i <= 100; i++)
        {
            if (primes[i])
            {
                Console.Write(i + " ");
            }
        }
    }
}
814 chars
36 lines

gistlibby LogSnag