49009新四不像手机论
输入年份和月份,输出对应的天数。
#include <stdio.h> int main() { int year, month, days; // 输入年份和月份 printf("请输入年份: "); scanf("%d", &year); printf("请输入月份: "); scanf("%d", &month); // 判断月份,并计算天数 switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: days = 31; break; case 4: case 6: case 9: case 11: days = 30; break; case 2: // 判断闰年 if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) days = 29; else days = 28; break; default: printf("无效的月份\\n"); return 1; // 退出程序,返回错误码 } // 输出结果 printf("%d年%d月有%d天\\n", year, month, days); return 0; // 返回成功码 }
这段代码通过输入年份和月份,使用语句判断每个月的天数,并考虑了闰年的情况。最后输出结果,澳门2025特马开跑 表示输入的年份和月份对应的天数。
- 本文固定链接: https://www.huaxiatt.com/post/6895.html
- 转载请注明: admin 于 红色航投 发表