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:
#include <stdio.h>int main(){int year;printf("Enter a year: ");scanf("%d",&year);if(year%4 == 0){if( year%100 == 0){// year is divisible by 400 is a leap yearif ( year%400 == 0)printf("%d is a leap year.", year);elseprintf("%d is not a leap year.", year);}elseprintf("%d is a leap year.", year );}elseprintf("%d is not a leap year.", year);return 0;}
Output:
Enter an year: 1975 1975 is not a leap year.