Search This Blog

Wednesday, December 15, 2010

Euler Problem 19

How many Sundays on the first of the month in the 20th Century from 1 Jan 1901 to 31 Dec 2000?

http://projecteuler.net/index.php?section=problems&id=19

Luckily C# can do this really easily!!

 

static void Main(string[] args)
        {

            int counter=0;
            DateTime d = new DateTime(1901,1,1);
           
            while (d.Year<2001)
            {
                if (d.DayOfWeek == DayOfWeek.Sunday && d.Day == 1)
                {
                    counter++;
                }

               d= d.AddDays(1);
            }

 

        Console.WriteLine(counter);
        Console.ReadLine();

        }

No comments: