Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Nhập vào năm và tháng của một năm bất kỳ, hãy viết chương trình in ra số ngày trong tháng đó.
- Ví dụ
- Với year = 2020, month = 2, đầu ra là "The number of days: 29".
- Giải thích: Do năm 2020 là năm nhuận nên tháng 2 có 29 ngày.
- Với year = 2019, month = 2, đầu ra là "The number of days: 28"
- Với year = 2017, month = 12, đầu ra là "The number of days: 31"
- Đầu vào: Năm và tháng được nhập từ bàn phím.
- Đầu ra: Số ngày trong tháng đó.
- Thời gian chạy: 0.5s */
- #include <stdio.h>
- int isLeapYear(int year)
- {
- if (year % 4 != 0)
- return 0;
- if (year % 100 != 0)
- return 1;
- if (year % 400 == 0)
- return 1;
- else
- return 0;
- }
- int numberOfDays(int year, int month) {
- switch (month)
- {
- case 1:
- case 3:
- case 5:
- case 7:
- case 8:
- case 10:
- case 12:
- /* phần cần thêm */
- case 4:
- case 6:
- case 9:
- case 11:
- /* phần cần thêm */
- case 2:
- if (isLeapYear(year))
- /* phần cần thêm */
- else
- /* phần cần thêm */
- }
- }
- int main(){
- int year;
- int month;
- scanf("%d%d", &year, &month);
- /* phần cần thêm */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement