C Program to Check Leap Year

CodingTute

C Program to Check Leap Year

In this example, you will learn to find a given year is a leap year or not. We all know a leap year has 366 days and comes on every fourth year.

C Program to Check Leap Year

#include <stdio.h>

int main()
{
    int year;
    
    printf("Enter a Year: ");
    scanf("%d", &year);
    
    if((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))
        printf("%d is a leap year.", year);
    else
        printf("%d is not a leap year.", year);

    return 0;
}

Output

Enter a Year: 2008
2008 is not a leap year.

Explanation

Firstly, read the input from the user and store it in a variable year.

We can find the leap year by the following conditions

  • A leap year is perfectly divisble by 400.
  • A leap year is perfectly divisible by 4 and not perfectly divisible by 100.

Follow us on Facebook, YouTube, Instagram, and Twitter for more exciting content and the latest updates.

Exit mobile version