使用python的for循环输出1900年——2000年所有闰年的年份
时间: 2023-10-20 09:05:25 浏览: 129
好的,以下是输出1900年——2000年所有闰年的年份的代码:
```python
for year in range(1900, 2001):
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
print(year)
```
这段代码使用了for循环,遍历了1900年到2000年之间的所有年份,并使用条件语句判断是否为闰年,如果是,则输出该年份。
你可以通过运行这段代码来得到所有闰年的年份。
相关问题
输出1900年到2000年中的所有闰年
在公历中,闰年是指能够被4整除但不能被100整除的年份,或者是能够被400整除的年份。因此,我们可以使用以下代码来输出1900年到2000年之间的所有闰年:
```python
for year in range(1900, 2001):
if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0):
print(year)
```
输出结果如下:
```
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
```
使用C语言编写一个程序输出1900-2000年之间的闰年
以下是使用C语言编写的程序,用于输出1900年至2000年之间的闰年:
```c
#include <stdio.h>
int main() {
int year;
printf("1900年至2000年之间的闰年为:\n");
for (year = 1900; year <= 2000; year++) {
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
printf("%d\n", year);
}
}
return 0;
}
```
这个程序通过循环从1900年到2000年,逐个检查每个年份是否是闰年,并输出所有符合条件的年份。根据闰年的定义,能够被4整除但不能被100整除的年份,或者能够被400整除的年份,都是闰年。