Monday 12 March 2012

check if a year is a leap year.

read this codes from Linux Device Driver, think it is good :)
record it here.

/*
 * return 1 if year is leap year, 0 otherwise.
 */
static int inline
leap_year(int year)
{
    return !(year % 400) || ( !(year % 4) && (year % 100)) ;
}

/* Number of days in each month (not leap year). */
static const char no_of_days[] =
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};