Leap Year Program In C

  • A leap year comes once in four years, in which February month has 29 days. With this additional day in February, a year becomes a Leap year .
  • Some leap years examples are - 1600, 1988, 1992, 1996, and 2000.
  • Although 1700, 1800, and 1900 are century years, not leap years.

To determine if a year is a leap year or not, the following criteria are applied:

  • The year must be a multiple of 4.
  • The year should be divisible by 400 and not divisible by 100.

By incorporating these criteria into your code, you can verify if a year is a leap year or not. Meeting the specified conditions will determine whether the year is indeed a leap year. You have the option to implement these conditions using if-else statements or by utilizing the logical operators && (and) and || (or).

How to find leap year using C programming?

By utilizing a C program, we can simplify the process of determining whether a year is a leap year or not.

Example

Explore the following example demonstrating how to verify a leap year by accepting user input:

Example

#include<stdio.h>
#include<conio.h>
void main() {
	int year;
	printf("Enter a year: ");
	scanf("%d", &year);
	if(((year%4==0) && ((year%400==0) || (year%100!==0))
	{
		printf("%d is a leap year", &year);
	} else {
		printf("%d is not a leap year", &year);
	}
	getch();
}

Output

See the below outputs for different input values:

Test 1:

Example

Enter a year: 2004
2004 is a leap year

Test 2:

Example

Enter a year: 1700
1700 is not a leap year

Example

In the following illustration, we will identify the leap years within a specified range of years, such as from 2000 to 2020. Review the demonstration below:

Example

#include<stdio.h>
#include<conio.h>
void main() {
	int startYear, endyear, i;
	printf ("Enter a year to start searching the leap years: ");
	scanf ("%d", &startYear);
	printf ("Enter a year to end the search of leap years: ");
	scanf ("%d", &endyear);
	printf ("Leap Years between %d to %d are: \n", &startYear, &endYear);
	for (i= startYear; i<= endYear, i++) 
	{
	     if(((i%4==0) && ((i%400==0) || (i%100!==0))
	     {
		  printf("%d \n", &i);
	     } 
	}
	getch();
}

Output

See the below output:

Example

Enter a year to start searching the leap years: 1950
Enter a year to end the search of leap years: 2020
Leap years between 1990 to 2020 are:
1992
1996
2000
2004
2008
2012
2016
2020

Input Required

This code uses input(). Please provide values below: