C Program to Check Leap Year

 

 A year is a leap year if −
  • It is evenly divisible by 100
    • If it is divisible by 100, then it should also be divisible by 400
  • Except this, all other years evenly divisible by 4 are leap years.
leap year in c
leap year in c

------------------------------------------------------------------


#include <stdio.h>

int main()
{
    int year;

    printf("Enter a year: ");
    scanf("%d",&year);

    if(year%4 == 0)
    {
        if( year%100 == 0)
        {
            // year is divisible by 400, hence the year is a leap year
            if ( year%400 == 0)
                printf("%d is a leap year.", year);
            else
                printf("%d is not a leap year.", year);
        }
        else
            printf("%d is a leap year.", year );
    }
    else
        printf("%d is not a leap year.", year);
    
    return 0;
}

 

Output:

Enter a year: 1900
1900 is not a leap year.

Leave a Reply