用C语言调用函数输出2000到3000年之间的闰年
时间: 2024-02-25 16:53:13 浏览: 41
好的,您可以使用以下C语言代码来实现:
```c
#include <stdio.h>
void leap_years(int start_year, int end_year) {
/*
This function prints out all the leap years between the start and end year (both inclusive).
*/
for (int year = start_year; year <= end_year; year++) {
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
printf("%d\n", year);
}
}
}
int main() {
leap_years(2000, 3000);
return 0;
}
```
这个程序定义了一个名为`leap_years()`的函数,这个函数接受两个整数参数:起始年份和结束年份,并将在这两个年份之间的所有闰年打印出来。然后在`main()`函数中,我们调用了`leap_years()`函数并传递2000和3000作为参数来输出2000到3000年之间的闰年。
相关问题
c语言中用leapyear函数输出2000年到2200年之间所有的闰年
可以使用以下代码实现:
```c
#include <stdio.h>
int leapyear(int year) {
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
return 1; // 是闰年
} else {
return 0; // 不是闰年
}
}
int main() {
int year;
for (year = 2000; year <= 2200; year++) {
if (leapyear(year)) {
printf("%d\n", year);
}
}
return 0;
}
```
其中,`leapyear` 函数判断一个年份是否为闰年,如果是闰年,返回1,否则返回0。在 `main` 函数中,使用循环遍历2000年到2200年之间的所有年份,然后调用 `leapyear` 函数判断是否为闰年,如果是,就输出该年份。
打印1000年到2000年之间的闰年 c语言
以下是一个用 C 语言编写的程序,用于打印 1000 年到 2000 年之间的所有闰年:
```c
#include <stdio.h>
int isLeapYear(int year) {
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0)
return 1;
else
return 0;
}
else
return 1;
}
else
return 0;
}
int main() {
int start = 1000;
int end = 2000;
printf("闰年列表:\n");
for (int year = start; year <= end; year++) {
if (isLeapYear(year))
printf("%d\n", year);
}
return 0;
}
```
在这个程序中,我们定义了一个名为 `isLeapYear` 的函数,用于判断一个年份是否为闰年。然后在 `main` 函数中,我们遍历从 1000 年到 2000 年的每个年份,调用 `isLeapYear` 函数来判断是否为闰年,并将结果打印出来。运行程序后,你将会看到打印出的闰年列表。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![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)