Leap Year Program in C - C Program to Check Leap Year



 c program to check leap year

Learn C - C tutorial - c program to check leap year - C examples - C programs

C Program to Check Leap Year

  • A year that has 366 days is called a leap year.
  • A year can be checked whether it is a leap year or not dividing the year by 4, 100 and 400.
  • If a number is divisible by 4 but not by 100 then, it is a leap year.
  • Also, if a number is divisible by 4, 100 and 400 then it is a leap year. Otherwise the year is not a leap year.

Sample Code

#include <stdio.h>
int main()
{
    int year=2000;
    printf("year:2000 \n");
    if(year%4 == 0)
    {
        if( year%100 == 0)
        {
            if ( year%400 == 0)
                printf("%d is a leap year.\n", year);
            else
                printf("%d is not a leap year\n", year);
        }
        else
            printf("%d is a leap year.\n", year );
    }
    else
        printf("%d is not a leap year.\n", year);
    return 0;
}

Output

year:2000 
2000 is a leap year.


View More Quick Examples


Related Searches to Leap Year Program in C - C Program to Check Leap Year