Q. C Program to Check Whether the Given Year is Leap Year or Not.


Here you will find an algorithm and program in C programming language to check whether the given year is leap year or not. First let us understand what is leap year?

Explanation : A leap year is a calendar year that contains an additional day added to keep the calendar year synchronized. A leap year is exactly divisible by 4, except for the century years (the years ending with 00). Century year is a leap year only if it is completely divisible by 400.

For Example : 2012 is Leap Year, 2014 is not a leap year.

Leap Year Algorithm


START
Step 1 → Initialize variable year
Step 3 → Check if year is divisible by 4 but not by 100, DISPLAY "leap year"
Step 4 → Check if year is divisible by 400, DISPLAY "leap year"
Step 5 → Otherwise, DISPLAY "not leap year"
STOP

C Program To Check Leap Year

#include <stdio.h>
int main() {
	int check_year=1998;
	if (check_year % 4 == 0) {
		if (check_year % 100 == 0) {
		// the check_year is a leap year if it is divisible by 400.
			if (check_year % 400 == 0)
				printf("%d is a leap year.", check_year);
			else
				printf("%d is not a leap year.", check_year);
			} 
		else
		printf("%d is a leap year.", check_year);
		} 
	else
		printf("%d is not a leap year.", check_year);
	return 0;
}

Output

1998 is not a leap year.