C program to check leap year

In this article, you will learn the concept of C program to check leap year i.e. whether a year is the leap year or not.

Leap year condition

A year that is exactly divisible by four is a leap year, except for years that are divisible by 100, but these century years are leap years if they are exactly divisible by 400.

Please go through following C programming articles to understand the concept of this example.

Easy C program to check leap year

#include <stdio.h>

int main ()
{
   int year;

   printf("Enter a year you want to check: ");
   scanf("%d", &year);
   //leap year condition
   if (year % 4 == 0)
   {
     if (year % 100 == 0)
     {
       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

C program to check leap year

[adsense1]

C program to check leap year in one line

#include <stdio.h>

int main()
{
   int year;

   printf("Enter a year you want to check: ");
   scanf("%d", &year);

   //leap year condition
   if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
      printf("%d is a leap year.", year);
   else
      printf("%d is not a leap year.", year);

   return 0;
}

Output first
leap year output 1

Output second

leap year output 2