C Program to Check Whether a Year is Leap or Not

If you are looking to know the concept about “C Program to Check Whether a Year is Leap or Not” then you are in the perfect tutorial. Shall we start the discussion to clarify it below? Come on! Let’s go.

C Program to Check Whether a Year is Leap or Not

C Program to Check Whether a Year is Leap or Not

Program Code

#include <stdio.h>
int main()
{
  int year;
 
  printf("Enter a year to check if it's a leap yearn");
  scanf("%d", &year);
 
  if (year%400 == 0) // Exactly divisible by 400, e.g., 1600, 2000
    printf("%d is a leap year.n", year);
  else if (year%100 == 0) // Exactly divisible by 100 and not by 400, e.g., 1900, 2100
    printf("%d isn't a leap year.n", year);
  else if (year%4 == 0) // Exactly divisible by 4 and neither by 100 nor 400, e.g., 2016, 2020
    printf("%d is a leap year.n", year);
  else // Not divisible by 4 or 100 or 400, e.g., 2017, 2018, 2019
    printf("%d isn't a leap year.n", year);  
   
  return 0;
}

Conclusion

I hope this article helps you to know the concept about “C Program to Check Whether a Year is Leap or Not“. If you face any issues please let me know via the comment section. Share this article with other C/C++ developers via social networks.

Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment