强化练习2:编程实现统计某年某月份的天数

来源:互联网 发布:手机摄影师调色软件 编辑:程序博客网 时间:2024/06/06 14:17

口诀:

一三五七八十腊1,3,5,7,8,10,12,31天永不差,
平年二月28,闰年二月29,其他月份三十天。


程序如下:

#include <stdio.h>int main(){int year;int month;scanf("%d %d", &year, &month);switch (month){case 1:case 3:case 5:case 7:case 8:case 10:case 12:printf("31\n");break;case 4:case 6:case 9:case 11:printf("30\n");break;case 2:if((year%4 == 0 && year%100 != 0) || (year%400 == 0)){printf("29\n");break;}else{printf("28\n");break;}default:printf("输入月份错误\n");break;}return 0;}



原创粉丝点击