?一.題目描述
比如輸入2001,2,29,輸出: 不合理 。因為平年的二月只有28天
比如輸入2000,6,31,輸出:不合理。因為6月是小月,只有30天。
二.思路分析
本題主要注意兩個問題:
1.閏年與平年的區分:閏年的2月有29天,平年只有28天
2.大月與小月的區別,大月一個月有31天,小月只有30天
?三.完整代碼
#define _CRT_SECURE_NO_WARNINGS//這一句必須放在第一行
#include <stdio.h>
int main()
{int year, month, day, a;printf("請輸入三個數字,分別是,年,月,日:\n");scanf("%d,%d,%d", &year, &month, &day);if (month >= 1 && month <= 12&&day >= 1){a = year % 4; //如果被四整除就是閏年,否則是平年if (month == 2)//2月if (a == 0)//閏年if (day <= 29)printf("合理\n");elseprintf("不合理\n");else//平年if (day <= 28)printf("合理\n");elseprintf("不合理\n");else if (month == 4 || 6 || 9 || 11)//小月if (day <= 30)printf("合理\n");elseprintf("不合理\n");else if (month == 1 || 3 || 5 || 7 || 8 || 10 || 12)//大月if (day <= 31)printf("合理\n");elseprintf("不合理\n");elseprintf("不合理\n");}elseprintf("不合理\n");return 0;
}
?四.運行結果
創作不易, 如果這份博客👍對你有幫助,可以給博主一個免費的點贊以示鼓勵。
歡迎各位帥哥美女點贊👍評論?收藏,謝謝!!!
如果有什么疑問或不同的見解,歡迎在評論區留言哦👀。
祝各位生活愉快?