试试这个
~
程序代码:
#include<stdio.h>
#include<stdio.h>
void Fun();
int main( void )
{
Fun();
return 0;
}
void Fun()
{
#define BEGIN 2000
#define END 3000
#define NEW_LINE 10
#define FOR_BEGIN(i,begin,end) \
for (i=begin;i!=end;++i)
#define IS_LEAP_YEAR(year) \
((((year)%4==0)&&((year)%100!=0))||((year)%400==0))
const char* format[]=
{
"%u ",
"\n"
};
#define PRINTF_YEAR(year,line_count) \
printf(format[!(line_count%(NEW_LINE+1))],(unsigned)(year-=!(line_count%(NEW_LINE+1))))
size_t i;
unsigned j=1;
FOR_BEGIN(i,BEGIN,END+1)
if (IS_LEAP_YEAR(i))
j+=!!PRINTF_YEAR(i,j);
puts("");
#undef BEGIN
#undef END
#undef NEW_LINE
#undef FOR_BEGIN
#undef PRINTF_YEAR
}
或者
~
程序代码:
#include<stdio.h>
void Fun();
int main( void )
{
Fun();
return 0;
}
void Fun()
{
#define BEGIN 2000
#define END 3000
#define NEW_LINE 10
#define FOR_BEGIN(i,begin,end) \
for (i=begin;i!=end;++i)
#define IS_LEAP_YEAR(year) \
((((year)%4==0)&&((year)%100!=0))||((year)%400==0))
const char* format[]=
{
"%u ",
"%u\n"
};
size_t i;
FOR_BEGIN(i,BEGIN,END+1)
if (IS_LEAP_YEAR(i))
{
#define LEAP_YEAR_NUM(year) \
((year)/4-(year)/100+(year)/400)
#define IS_NEW_LINE(begin,year) \
(!((LEAP_YEAR_NUM(year)-LEAP_YEAR_NUM(begin)+1)%NEW_LINE))
#define PRINTF_YEAR(year) \
printf(format[IS_NEW_LINE(BEGIN,year)],(unsigned)year)
PRINTF_YEAR(i);
#undef LEAP_YEAR_NUM
#undef IS_NEW_LINE
#undef PRINTF_YEAR
}
puts("");
#undef BEGIN
#undef END
#undef NEW_LINE
#undef FOR_BEGIN
}
[此贴子已经被作者于2018-1-12 15:12编辑过]