assignment-p-04.c (1003B)
1 /* Write a C program that takes an integer input representing a month (1 to 12) and a year. 2 Use a switch statement to display the number of days in that month, considering leap years. */ 3 4 #include <stdio.h> 5 6 int main() 7 { 8 int month, year, days; 9 printf("Enter the month (1 to 12) and year: "); 10 scanf("%d %d", &month, &year); 11 12 switch (month) 13 { 14 case 1: // jan 15 case 3: // mar 16 case 5: // may 17 case 7: // july 18 case 8: // aug 19 case 10: // oct 20 case 12: // dec 21 days = 31; 22 break; 23 case 4: // apr 24 case 6: // jun 25 case 9: // sep 26 case 11: // nov 27 days = 30; 28 break; 29 case 2: // feb 30 if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) 31 { 32 days = 29; 33 } 34 else 35 { 36 days = 28; 37 } 38 break; 39 default: 40 printf("\nYou entered something wrong."); 41 return 0; 42 } 43 44 printf("\nNumber of days: %d", days); 45 return 0; 46 }