Here a simple C program to check leap year is given ,which takes any year from user and after execution it check that input year is leap year or not.As you know all years which are perfectly divisible by 4 are leap years except for century years( years ending with 00 ) which is a leap year only it is perfectly divisible by 400. For example: 2016, 2008, 1972 etc are leap year but, 1973, 2009 etc are not leap year. Similarly, 1200, 1600, 2000, 2400 are leap years but, 1700, 1800, 1900 etc are not.So this c program to check leap year use this concept and check them.This program asks user to enter a year and this program checks whether that year is leap year or not.
C program to check leap year
#include <stdio.h>
int main() { int year; printf("Enter a year: "); scanf("%d",&year); if(year%4 == 0) { if( year%100 == 0) /* Checking for a century year */ { if ( year%400 == 0) printf("%d is a leap year.", year); else printf("%d is not a leap year.", year); } else printf("%d is a leap year.", year ); } else printf("%d is not a leap year.", year); return 0; }
Output 1 :
Enter a year : 2004
2004 is a leap year
output 2
Enter a year : 2005
2005 is not a leap year
Enter year: 2000 2000 is a leap year.
Enter year: 2000 2000 is a leap year.Enter year: 2000 2000 is a leap year.