Advertisement
pdaogu

HW9.2

Nov 6th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int isLeapYear (int year) {
  4.     return ((year % 4 == 0) && (year % 100 == 1) || (year % 400 == 0));
  5. }
  6.  
  7. int DaysOfMonth (int month, int year) {
  8.     switch (month) {
  9.         case 4:
  10.         case 6:
  11.         case 9:
  12.         case 11:
  13.             return 30;
  14.         case 2:
  15.             if (isLeapYear(year))
  16.                 return 29;
  17.             else
  18.                 return 28;
  19.         case 1:
  20.         case 3:
  21.         case 5:
  22.         case 7:
  23.         case 8:
  24.         case 10:
  25.         case 12:
  26.             return 31;
  27.         default:
  28.             return -1;
  29.  
  30.     }
  31. }
  32.  
  33. int main () {
  34.     int month, year;
  35.     printf("Enter month: ");
  36.     scanf("%d", &month);
  37.     printf("Enter year: ");
  38.     scanf("%d", &year);
  39.     printf("Number days of %d/%d is: %d", month, year, DaysOfMonth(month, year));
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement