Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Sir/Madam,

Please Help how to identify the Leap Year.
Posted
Comments
Zoltán Zörgő 21-Oct-13 5:44am    
You could have found the answer in 10 seconds with google :(
thatraja 21-Oct-13 6:00am    
One of the old programming questions.

you can use build method in datetime class. it will return a true/false.
C#
DateTime.IsLeapYear(2013)
 
Share this answer
 
v3
Comments
Zoltán Zörgő 21-Oct-13 5:43am    
That's it: simple and easy.
ridoy 21-Oct-13 6:28am    
my 5 too.
And if you don't want to use DateTime.IsLeapYear() then have a try with it:
C#
try
{
   Console.Write("Please Enter the Year: ");
   int year = int.Parse(Console.ReadLine());
   
   if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
   {
      Console.WriteLine("The year {0}, is a Leap Year", year);
   }
   else
   {
      Console.WriteLine("The year {0}, is not a Leap Year", year);
   } 
}
catch (Exception ex)
{
   Console.WriteLine(ex.Message);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900