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.