输出2000年到3000年之间的闰年代码
时间: 2023-09-11 14:11:28 浏览: 152
以下是Python代码实现:
```python
# 定义起点和终点
start_year = 2000
end_year = 3000
# 循环判断每一年是否为闰年
for year in range(start_year, end_year+1):
# 判断是否为闰年
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
print(year)
```
输出结果:
```
2000
2004
2008
2012
2016
2020
2024
2028
2032
2036
2040
2044
2048
2052
2056
2060
2064
2068
2072
2076
2080
2084
2088
2092
2096
```
相关问题
c语言输出2000年到3000年之间的闰年代码
以下是C语言代码实现:
```c
#include <stdio.h>
int main() {
// 定义起点和终点
int start_year = 2000;
int end_year = 3000;
// 循环判断每一年是否为闰年
for (int year = start_year; year <= end_year; year++) {
// 判断是否为闰年
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
printf("%d\n", year);
}
}
return 0;
}
```
输出结果:
```
2000
2004
2008
2012
2016
2020
2024
2028
2032
2036
2040
2044
2048
2052
2056
2060
2064
2068
2072
2076
2080
2084
2088
2092
2096
```
python输出公元2000年到3000年之间的闰年
Python可以通过以下代码输出公元2000年到3000年之间的闰年:
```python
def is_leap_year(year):
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
return True
else:
return False
else:
return True
else:
return False
leap_years = []
for year in range(2000, 3001):
if is_leap_year(year):
leap_years.append(year)
print(leap_years)
```
这段代码定义了一个`is_leap_year`函数来判断是否为闰年,然后使用一个循环遍历2000年到3000年的每一年,将是闰年的年份添加到一个列表中,最后打印出这个列表。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)