用C语言编写一个程序,用for循环的嵌套方式编写程序,输出从公元2000年到3000年所有闰年的年份

发布时间:2021-03-07 18:37:48

用C语言编写一个程序,用for循环的嵌套方式编写程序,输出从公元2000年到3000年所有闰年的年份,每行输出10个年份.判定闰年的条件是:(1)年份能被4整除,但不能被100整除,则是闰年;(2)年份能被400整除也是闰年.(提示:循环变量从2000变化到3000,然后去判断每一个年份是否为闰年,若是,则输出.由于每行只能输出10年份,还要定义一个整型变量用于计数)

网友回答

#include <iostream>
#include <stdlib.h>
int main()
{int start = 2000;
int end = 3000;
int i = 0;
for(start=2000;start<=end;start++)
{if((start%4 == 0) &&(start%100 != 0) || (start%400 == 0))
{printf("%d,",start);
if(i == 9)
{i=0;printf("\n");
}else{i++;}}else{}}return 0;
}
以上问题属网友观点,不代表本站立场,仅供参考!