Determine Leap Year

Today is a special day which comes only after four years -29th Feb. So I thought I should write something about leap year.
First, what is leap year?
· The year must be divisible by 4 and must NOT be divisible by 100.
· The year must be divisible by 400.
In C# we have already defined function name
IsLeapYear(int year)
It is static fuction.
Namespace: System
 Assembly:  mscorlib (in mscorlib.dll)
Parameters:
year
Type: System.Int32
A 4-digit year.
Return Value:
Type: System.Booleantrue if year is a leap year; otherwise, false.
Usage:

Example 
Determine how many leap year from within a range of two years.

public int countLeapYear(int startYear,int EndYear)
{
     int intCount = 0;

    for (int year = startYear; year <= EndYear; year++)
     {
        if (DateTime.IsLeapYear(year))
       {
          intCount = intCount + 1;
       }
    }
      return intCount;
 }


Now you can call this function by passing two year values as parameters.

suppose I want from 2001 to 2099 how many leap year

countLeapYear(2001,2099)

It will return 24.

cheers.....
Determine Leap Year Determine Leap Year Reviewed by kamal kumar das on February 29, 2012 Rating: 5

No comments:

ads 728x90 B
Powered by Blogger.