Home / Programs / Write a program that uses a function to check whether a given year is a leap year or not.
Programming Example

Write a program that uses a function to check whether a given year is a leap year or not.

👁 1,019 Views
💻 Practical Program
📘 Step by Step Learning
Write a program that uses a function to check whether a given year is a leap year or not.

Program Code


#include <stdio.h>

int leap_yr(int);
int main(void)
{

	int year, yes;
	printf("\n Enter the Year: ");
	scanf("%d",&year);
	yes=leap_yr(year);
	if(yes)
		printf("\n It is a leap year");
	else
		printf("\n It is NOT a leap year");
	return 0;

}


int leap_yr(int yr)
{
	if((yr%4==0)&&( yr%100!=0)||yr%400 ==0)
			return 1;
	else
			return 0;

}
 

Output


 Enter the Year: 2100

 It is NOT a leap year
 

Explanation

None

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.