Wednesday 24 April 2013

Enter a year and determine whether the year is a leap year or not. A leap year is a noncentury year that is divisible by 4. A century year is a year divisible by 100, such as 1900. A century year, which is divisible by 400, such as 2000, is also a leap year. Hint: If a year is divisible by 4 and is not divisible by 100 or divisible by 400, it is a leap year. (Duration: 30 min)


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Leap
{
    class Program
    {
        public static void Main(string[] args)
        {
            int nYear;
            Console.WriteLine("Please enter the year");
            nYear = Convert.ToInt32(Console.ReadLine());
            if (nYear % 400 == 0 || (nYear % 100 != 0 && nYear % 4 == 0))
            {
                Console.WriteLine("This is a leap year");
            }
            else
            {
                Console.WriteLine("This is not a leap year");
            }
        }
    }
}

No comments:

Post a Comment