A Program to Check a Leap Year

In this example, we are giving a program which is useful to check whether an year given by the user is a leap year or not.


Program to check an year is a leap year or not:

  1. #include <stdio.h>
  2. int main()
  3. {
  4. int year;
  5. printf("Enter a year: ");
  6. scanf("%d",&year);
  7. if(year%4 == 0)
  8. {
  9. if( year%100 == 0)
  10. {
  11. // year is divisible by 400 is a leap year
  12. if ( year%400 == 0)
  13. printf("%d is a leap year.", year);
  14. else
  15. printf("%d is not a leap year.", year);
  16. }
  17. else
  18. printf("%d is a leap year.", year );
  19. }
  20. else
  21. printf("%d is not a leap year.", year);
  22. return 0;
  23. }

Output:

Enter an year: 1975
1975 is not a leap year.