C Program to Check Leap Year

This C program checks whether given year is leap year or not. A leap year is a year which is divisible by 4 and not divisible by 100 OR it a divisible by 400.

C Program to Check Given Year is Leap Year or Not

/* C code to check whether given year is leap year or not */

#include<stdio.h>

int main()
{
    int year;
 
    printf("\n Enter the year:-");
    scanf("%d",&year);

    if (year%4==0 && year%100!=0)
        printf("\n The year %d leap year \n \n",y);
    else
        printf("\n The year %d not leap year. \n \n", year);

    return 0;
}

Output:

 Enter the year:-2012

 The year 2012 leap year.

Explanation:

Accept the year from user store it into variable year. Use control statement if to check if given year
Case 1: is divisible by 400 OR Case 2: is divisible by 4 and not divisible by 100
by using modulus operator ( % ) in C. If any one of above two cases is true then the year is a leap year.

C program to check leap year using Function

/* Aim: Write a function for the following function prototype
void Leap(int l) */ 

#include<stdio.h>

void Leap(int l);  // Leap Function Prototype

void main()
{
	int l;
	printf("\n Enter any year:- ");
	scanf("%d",&l);

	Leap(l);
}

// Leap Function

void Leap(int l)
{
	if(l%4==0)
		printf("\n %d is leap year \n \n",l);
	else
		printf("\n %d is not leap year \n \n",l);

}

Output

 Enter any year:- 2012

 2012 is leap year