c语言 用宏定义条件编译方法输出1900-2000年中的闰年

如题所述

闰年规则为,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);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-07-27
直接用for循环可以不?
#include <stdio.h>
main(){
int year;
for(year = 1900;year <= 2000;year++){
if((year % 4 == 0 && year % 400 != 0)||year % 400 == 0 ){
printf("%d,",year);
}
}
}追问

用宏定义

本回答被网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网