April 25, 2020

How to write a program in C# to find leap year.

Enter a year and determine whether the year is a leap year or not. A leap year is a non century 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.

How to write a program in C# to find leap year.

Sample Solution

C# Sharp Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class LeapYear
    {
        int y;
        public void Readdata()
        {
            Console.WriteLine("Enter the year in four Digit :");
            y = Convert.ToInt32(Console.ReadLine());
        }
        public void leap()
        {
            if ((y % 4 == 0 && y % 100 != 0))
            {
                Console.WriteLine("{0} is a leap year", y);
            }
            else
            {
                Console.WriteLine("{0} is not Leap year ", y);
            }
        }
        static void Main(string[] args)
        {
            LeapYear obj = new LeapYear();
            obj.Readdata();
            obj.leap();
            Console.ReadLine();

        }
    }
}

                                                             Sample Output

How to write a program in C# to find leap year, Leap year





No comments:

Post a Comment