Advertisement

Latest Post

Sunday, 1 January 2017

How to Find A Year is A Leap Year or Not [C#]

Write a program in C# that tells whether a given year is a leap year or not.

Following is the simple C# code :
class Lab
    {
        static void Main(string[] args)
        {

            int year;
            Console.Write("Enter a year : ");
            year = Convert.ToInt32(Console.ReadLine());
            if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
            {
                Console.WriteLine("{0} is a Leap Year", year);
            }
            else
            {
                Console.WriteLine("{0} is not a Leap Year", year);
            }
            Console.ReadLine();

        }
    }

Output:-

Government Jobs