100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > c语言判断闰年并输出该月天数 C语言宏定义实现闰年判断并输出指定月的天数...

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

时间:2022-07-27 02:14:43

相关推荐

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

程序如下:

#include

#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;

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。