//******************************************************************
// LeapYear program
// This program inputs at year and prints whether the year
// is a leap year or not
//******************************************************************
#include <iostream> // Access output stream
usingnamespace std;
bool isLeapYear( int ); // Prototype for subalgorithm
int main() {
int year;
cout << "Enter a year AD, for example, 1997."
<< endl; // Prompt for input
cin >> year; // Read year
if (isLeapYear ( year ) ) // Test for leap year
cout << year << " is a leap year." << endl;
else
cout << year << " is not a leap year." << endl;
return 0;
}
// *****************************************************************
bool isLeapYear( int year )
// IsLeapYear returns true if year is a leap year and
// false otherwise.
{
if (year % 4 != 0) // Is year not divisible by 4?
returnfalse; // If so, can't be a leap year
elseif (year % 100 != 0) // Is year not a multiple of 100?
returntrue; // If so, is a leap year
elseif (year % 400 != 0) // Is year not a multiple of 400?
returnfalse; // If so, then is not a leap year
elsereturntrue; // Is a leap year
}