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 <iostream>
using namespace std;
int main()
{
int year;
cout << "Enter a year: ";
cin >> year;
if(year%4 == 0)
{
if( year%100 == 0)
{
// year is divisible by 400 is a leap year
if ( year%400 == 0)
cout << d << "is a leap year.";
else
cout << d << "is not a leap year.";
}
else
cout << d << "is a leap year.";
}
else
cout << d << "is not a leap year.";
return 0;
}
Output:
Enter an year: 1975 1975 is not a leap year.