Wednesday, 28 October 2015

C# Program to Check Whether the Entered Year is a Leap Year or Not?

class leapyear
    {
        static void Main(string[] args)
        {
            leapyear obj = new leapyear();
            obj.rd();
            obj.leap();
        }
        int y;
        public void rd()   //rd=readdata
        {
            Console.WriteLine("Enter the Year in Four Digits : ");
            y = Convert.ToInt32(Console.ReadLine());
        }
        public void leap()
        {
            if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0))
            {
                Console.WriteLine("{0} is a Leap Year", y);
            }
            else
            {
                Console.WriteLine("{0} is not a Leap Year", y);
            }
            Console.ReadLine();
        }
    }
-------------------
OUTPUT
Enter the Year in Four Digits : 2002
2002 is not a Leap Year
-------------------

2 comments: