c语言中输出1900~2000年中闰年年份

如题所述

#include<stdio.h>
int main()
{
int i;
for(i=1900;i<=2000;i++)
{
if(i%4==0 && i%100!=0 || i%400==0)
//闰年:年数能被4但是不能被100整除,或者能被400整除的。

printf("%d\n",i);
}
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-01-13
闰年规则为,4年一闰,百年不闰,四百年再闰。
根据此规则,编写判断闰年的宏函数如下:
#define
is_leap(x)
(x%400==0
||
(x%4==0
&&
x%100!=0))
根据题意,对1900到2000进行遍历,判断输出即可。
#define _for(x,s,e) for(x=s;x<=e; x++)
#define out(x) printf("%d,",x)
#define is_leap(x) (x%400==0 || (x%4==0 && x%100!=0))
int main()
{
int i;
_for(i,1900,2000)
if(is_leap(i))
out(i);
}
第2个回答  2012-03-04
闰年:年数能被4但是不能被100整除,或者能被400整除的。
#include <stdio.h>

int check_leap(int year) //判断闰年
{
if( (year%100)==0 )
{
if( (year%400)==0 )
return 1;
}
else if( (year%4)==0 )
return 1;
return 0;
}

void print_leap_year(int start, int end)
{
int i;
for(i=start;i<=end;i++)
{
if(check_leap(i)==1)
printf("%d is leap year\n");
}
}

int main(void)
{
print_leap_year(1900,2000);
return 0;
}本回答被网友采纳
第3个回答  2012-03-04
for(i = 1900; i< 2001; i++)
{
if(i %4 == 0)
printf(" %d 是闰年\n",i);
}

//
i = 1900;
do{
printf("%d 是闰年\n", i);
i+=4;
}while(i<2001);
第4个回答  2020-05-09
闰年:年数能被4但是不能被100整除,或者能被400整除的。
#include
<stdio.h>
int
check_leap(int
year)
//判断闰年
{
if(
(year%100)==0
)
{
if(
(year%400)==0
)
return
1;
}
else
if(
(year%4)==0
)
return
1;
return
0;
}
void
print_leap_year(int
start,
int
end)
{
int
i;
for(i=start;i<=end;i++)
{
if(check_leap(i)==1)
printf("%d
is
leap
year\n");
}
}
int
main(void)
{
print_leap_year(1900,2000);
return
0;
}