C Program to Check Whether a Given Year is Leap Year or Not

Program (Using if-else)


#include<stdio.h>
#include<conio.h>

void main()
{
	 int y;
	 clrscr();
	 printf("Enter year: ");
	 scanf("%d", &y);
	 if( (y%400 == 0) || (y%4 == 0 && y%100 != 0) )
	 {
	  printf("%d is a leap year.", y);
	 }
	 else
	 {
	  printf("%d is not a leap year.", y);
	 }
	 getch();
}

Output of the above program :

Run 1:
----------------
Enter year: 3000 ↲
3000 is not a leap year.

Run 2:
----------------
Enter year: 2004 ↲
2004 is not a leap year.

Note: ↲ indicates ENTER is pressed.

Program (Using if-else-if)

#include<stdio.h>
#include<conio.h>

void main()
{
	 int y;
	 clrscr();
	 printf("Enter year: ");
	 scanf("%d", &y);
	 if(y%400 == 0)
	 {
	  printf("%d is a leap year.", y);
	 }
	 else if(y%4 == 0 && y%100 != 0)
	 {
	  printf("%d is a leap year.", y);
	 }
	 else
	 {
	  printf("%d is not a leap year.", y);
	 }
	 getch();
}

Output of the above program :

Run 1:
----------------
Enter year: 3000 ↲
3000 is not a leap year.

Run 2:
----------------
Enter year: 2004 ↲
2004 is not a leap year.

Note: ↲ indicates ENTER is pressed.