判断闰年

发布时间 2023-04-12 20:57:28作者: 轻挼草色

一、问题描述:

输入一个年份,判断是否闰年。

二、设计思路:

    1. 输入一个年份;
    2. 判断是否为闰年;
    3. 是闰年输出"  is a leap year",反之,则输出"  is not a leap year"。

三、

 

四、伪代码实现:

if year是闰年
    then 输出“所输年份 is a leap year”
    else 输出“所属年份 is not a leap year”

 

五、代码实现

 1 #include <iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     int year;
 6     bool isLeapYear;
 7 
 8     cout << "Enter the year: ";
 9     cin >> year;
10     isLeapYear = ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0));
11     if (isLeapYear)
12         cout << year << "is a leap year" << endl;
13     else
14         cout << year << "is not a leap year" << endl;
15 
16     return 0;
17 }