您的位置:首页 > 编程语言 > C语言/C++

C语言宏定义实现闰年判断并输出指定月的天数

2013-03-23 13:32 309 查看
程序如下:

 

#include <stdio.h>
#define LEAP_YEAR(year, month)\
do{\
if((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))\
{\
printf("%d is Leap!\n", year);\
}\
else\
{\
printf("%d is not Leap!\n", year);\
}\
switch(month)\
{\
case 1:\
case 3:\
case 5:\
case 7:\
case 8:\
case 10:\
case 12:\
printf("month %d is 31 days\n", month);\
break;\
case 4:\
case 6:\
case 9:\
case 11:\
printf("month %d is 30 days\n", month);\
break;\
case 2:\
if(year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))\
printf("month %d is 29 days\n", month);\
else\
printf("month %d is 28 days\n", month);\
break;\
default:\
printf("The input month is wrong!\n");\
break;\
}\
}while(0)

int main(void)
{
int year, month;
printf("Input the year:");
scanf("%d", &year);
printf("Input the month:");
scanf("%d", &month);

LEAP_YEAR(year, month);

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: