Advertisement
ppupil2

C_prac-func-cond

Feb 27th, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. /* 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 đó.
  2.  
  3. Ví dụ
  4. Với year = 2020, month = 2, đầu ra là "The number of days: 29".
  5. Giải thích: Do năm 2020 là năm nhuận nên tháng 2 có 29 ngày.
  6. Với year = 2019, month = 2, đầu ra là "The number of days: 28"
  7. Với year = 2017, month = 12, đầu ra là "The number of days: 31"
  8. Đầu vào: Năm và tháng được nhập từ bàn phím.
  9. Đầu ra: Số ngày trong tháng đó.
  10. Thời gian chạy: 0.5s */
  11.  
  12.  
  13. #include <stdio.h>
  14.  
  15. int isLeapYear(int year)
  16. {
  17.    if (year % 4 != 0)
  18.       return 0;
  19.    if (year % 100 != 0)
  20.       return 1;
  21.    if (year % 400 == 0)
  22.       return 1;
  23.    else
  24.       return 0;
  25. }
  26.  
  27. int numberOfDays(int year, int month) {
  28.     switch (month)
  29.     {
  30.     case 1:
  31.     case 3:
  32.     case 5:
  33.     case 7:
  34.     case 8:
  35.     case 10:
  36.     case 12:
  37.         /* phần cần thêm */
  38.     case 4:
  39.     case 6:
  40.     case 9:
  41.     case 11:
  42.         /* phần cần thêm */
  43.     case 2:
  44.         if (isLeapYear(year))
  45.             /* phần cần thêm */
  46.         else
  47.             /* phần cần thêm */
  48.     }
  49. }
  50.  
  51. int main(){
  52.     int year;
  53.     int month;
  54.     scanf("%d%d", &year, &month);
  55.     /* phần cần thêm */
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement