C++ Example - Determining Leap Year
The user inputs a year, and determine whether that year is a leap year.
Example
#include <iostream>
using namespace std;
int main()
{
int year;
cout << "Enter a year:";
cin >> year;
if (year % 4 == 0)
{
if (year % 100 == 0)
{
//// Here, if divisible by 400, it is a leap year
if (year % 400 == 0)
cout << year << "is a leap year";
else
cout << year << "is not a leap year";
}
else
cout << year << "is a leap year";
}
else
cout << year << "is not a leap year";
return 0;
}
The output result of the above program execution is:
输入年份: 1990 1990 不是闰年other extensions