LeapYear:- For any year to be a leap year, it is necessary to fulfill these two conditions. The first is that the particular year can be divided by the number of 4. For example, 2000 can be divided by 4. Similarly, 2004, 2008, 2012, 2016,2020 can also divided by 4 so these year is leap year. Secondly, if a year is divisible by the number of 100, then it is not a leap year but if the same year is completely divided by the number of 400 it will be called a leap year. For example, the number 1300 is divided by 100 but cannot be divided by 400. Similarly 2000 can be divided by 100 but it is also completely divided by 400, so it will be called leap year.
Algorithm:-
(1)start
(2)Take a year from user
(3)if year is divisible by 4 and not divisible by 100 or year is divisible by 400 then year is leap year else year is not leap year
(4)stop
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CheckLeapYear
{
class Program
{
static void Main(string[] args)
{
int y;
Console.Write("Enter the year in four digits : ");
y= Convert.ToInt32(Console.ReadLine());
if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0))
{
Console.WriteLine(y + " is a Leap Year ");
}
else
{
Console.WriteLine(y + " is not a Leap Year ");
}
Console.ReadKey();
}
}
}
Output:-
Enter the year in four digits : 2000
2000 is a Leap Year
Enter the year in four digits : 2015
2015 is not a Leap Year
0 टिप्पणियाँ