c++if语句判断闰年
时间: 2023-12-22 10:29:28 浏览: 129
c++判断闰年
以下是用C++的if语句判断闰年的示例代码:
```cpp
#include <iostream>
using namespace std;
int main() {
int year;
bool leap;
cout << "请输入年份:";
cin >> year;
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0)
leap = true;
else
leap = false;
} else
leap = true;
} else
leap = false;
if (leap)
cout << year << "是闰年" << endl;
else
cout << year << "不是闰年" << endl;
return 0;
}
```
阅读全文