Program to check for leap year in C

December 05, 2014 0 Comments

Before writing the program let us see "What is a leap year?"
Definition: A year which satisfies one of the following two cases:

  • It is divisible by 4 and should not be divisibly by 100 
  • Divisible by 400
If one of the condition is true, it is a leap year. But, if both condition are false, the year is not a leap year. The following table shows whether a year is a leap year or not along with the reasons:

Leap year Table

The partial code for this can be written as follows:

if(year % 4 == 0 && year % 100 !=0) || (year % 400 == 0)
printf ("%d is a leap year \n",year);
printf("%d is not a leap year \n");

The complete program is shown below:

void main( )
int year;
printf("Enter the year");
if((year %4==0 && year %100!=0 ) !! (year %400 == 0))
printf("%d is a leap year ",year);
printf("%d is not a leap year",year);

Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google