作业帮 > 综合 > 作业

用C语言编写一个程序,用for循环的嵌套方式

来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:综合作业 时间:2024/05/16 08:40:33
用C语言编写一个程序,用for循环的嵌套方式
编写程序,输出从公元2000年到3000年所有闰年的年份,每行输出10个年份.判定闰年的条件是:
(1)年份能被4整除,但不能被100整除,则是闰年;
(2)年份能被400整除也是闰年.
(提示:循环变量从2000变化到3000,然后去判断每一个年份是否为闰年,若是,则输出.由于每行只能输出10年份,还要定义一个整型变量用于计数)
用C语言编写一个程序,用for循环的嵌套方式
#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;
}