1364.找闰年
时间限制: 1000 MS 内存限制: 65536 K
提交数: 853 (0 users) 通过数: 295 (279 users)
问题描述
再来,小明回想到,自己不是曾经出了一题闰年的题来考自己的师傅吗?那我何不就改改,然后自己做?他想:要不我就输出给定的任一一个时间段之间的闰年吧!
输入格式
输入两个整数m,n,代表两个年份。保证m<n。1000<m<n<3000
输出格式
输出[m,n]之间的所有闰年,每行5个
样例输入
1998 2015
样例输出
2000 2004 2008 2012
来源
时间限制: 1000 MS 内存限制: 65536 K
提交数: 853 (0 users) 通过数: 295 (279 users)
问题描述
再来,小明回想到,自己不是曾经出了一题闰年的题来考自己的师傅吗?那我何不就改改,然后自己做?他想:要不我就输出给定的任一一个时间段之间的闰年吧!
输入格式
输入两个整数m,n,代表两个年份。保证m<n。1000<m<n<3000
输出格式
输出[m,n]之间的所有闰年,每行5个
样例输入
1998 2015
样例输出
2000 2004 2008 2012
来源
xmu
#include <stdio.h>
int is_leap(int year)
{
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
return 1;
else
return 0;
}
int main()
{
int m, n;
int year;
int column_count;
scanf("%d %d", &m, &n);
column_count = 0;
for (year = m; year <= n; ++year)
{
if (is_leap(year))
{
printf("%d ", year);
column_count++;
if (column_count == 5)
{
printf("\n");
column_count = 0;
}
}
}
return 0;
}