Online Snippets Library

Check if a year is leap year or not

If Year is divisible by 4 and but not 100 OR year is divisible by 400,Then It is leap year otherwise It is not leap year.

C Program
#include <stdio.h>

int main() {
   int year;
   year = 2017;
   
   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

2017 is not a leap year