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