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 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;

}
 
                        

🖥 Program Output


 Enter the Year: 2100

 It is NOT a leap year
 
                            

📘 Explanation

None
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.