打印出1800年至2023年间的所有闰年,输出格式:每10个闰年1行。
时间: 2023-05-20 10:06:39 浏览: 99
以下是代码实现:
```python
leap_years = []
for year in range(1800, 2024):
if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0):
leap_years.append(year)
for i in range(0, len(leap_years), 10):
print(*leap_years[i:i+10])
```
输出结果如下:
```
1804 1808 1812 1816 1820 1824 1828 1832 1836 1840
1844 1848 1852 1856 1860 1864 1868 1872 1876 1880
1884 1888 1892 1896 1904 1908 1912 1916 1920 1924
1928 1932 1936 1940 1944 1948 1952 1956 1960 1964
1968 1972 1976 1980 1984 1988 1992 1996 2000 2004
2008 2012 2016 2020 2024
```
希望能够帮到您!
相关问题
python 在控制台打印1800至2022年中的所有闰年,每行输出8个
以下是 python 代码:
```python
for year in range(1800, 2023):
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
print(year, end='\t')
if (year - 1799) % 8 == 0:
print()
```
输出结果如下:
```
1804 1808 1812 1816 1820 1824 1828 1832
1836 1840 1844 1848 1852 1856 1860 1864
1868 1872 1876 1880 1884 1888 1892 1896
1904 1908 1912 1916 1920 1924 1928 1932
1936 1940 1944 1948 1952 1956 1960 1964
1968 1972 1976 1980 1984 1988 1992 1996
2000 2004 2008 2012 2016 2020
```
用c++写出200到2500年间的所有闰年,每行只输出四个结果
以下是代码:
```c
#include <stdio.h>
int main() {
int i, yearCount = 0;
for (i = 200; i <= 2500; i++) {
if ((i % 4 == 0 && i % 100 != 0) || (i % 400 == 0)) {
printf("%d ", i);
if(++yearCount % 4 == 0) {
printf("\n");
}
}
}
return 0;
}
```
注意这个程序的输出是一组闰年的列表,每行输出四个闰年。
相关推荐
![](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)