Write a C# program to check Leap year?

Write a C# program to check Leap year?

Last updated:11/21/2021 10:37:32 PM

1 Answers

Ashutosh Kumar Verma
Ashutosh Kumar Verma

Leap Year:

Leap year is a year in which the day is 366 instead of 365 because there are 29 days in February month. We can find all the leap year by using the following C# program.

Program:

using System;					

public class Program
{
 public static void Main()
 {
int num=2018, i;
  if((num%400==0)||(num%4==0 && num%100!=0))
  {
  Console.WriteLine('is Leap Year');
  }else
  {
  Console.WriteLine('not Leap Year');
  }
}
}
Output:     not Leap Year

Program for Taking input a year by user to check that is Leap year or not.

using System;

public class Program
{
 public static void Main()
 {
  int num;
  Console.WriteLine('Enter an year to check whether is Leap year or not');
  num=int.Parse(Console.ReadLine());
  if(num%4==0)
  {
   if(num%100!=0)
   {
    if(num%400==0)
    {
      Console.WriteLine(num+' is a Leap year');
    }else
     Console.WriteLine(num+' is a Leap year');
   }else
   {
   Console.WriteLine(num+' not a leap year');
   }
  }else
  {
  Console.WriteLine('not a leap year');
  }
 }
}

 Output:

Enter an year to check whether is Leap year or not

2020
2020 is a Leap year


Answer