c program to find number of days in a month using switch case

Solutions on MaxInterview for c program to find number of days in a month using switch case by the best coders in the world

showing results for - "c program to find number of days in a month using switch case"
Edward
06 Jan 2020
1/**
2 * C program to print number of days in a month using switch case 
3 */
4
5#include <stdio.h>
6
7int main()
8{
9    int month;
10
11    /* Input month number from user */
12    printf("Enter month number(1-12): ");
13    scanf("%d", &month);
14
15    switch(month)
16    {
17        case 1: 
18            printf("31 days");
19            break;
20        case 2: 
21            printf("28/29 days");
22            break;
23        case 3: 
24            printf("31 days");
25            break;
26        case 4: 
27            printf("30 days");
28            break;
29        case 5: 
30            printf("31 days");
31            break;
32        case 6: 
33            printf("30 days");
34            break;
35        case 7: 
36            printf("31 days");
37            break;
38        case 8: 
39            printf("31 days");
40            break;
41        case 9: 
42            printf("30 days");
43            break;
44        case 10: 
45            printf("31 days");
46            break;
47        case 11: 
48            printf("30 days");
49            break;
50        case 12: 
51            printf("31 days");
52            break;
53        default: 
54            printf("Invalid input! Please enter month number between 1-12");
55
56    }
57
58    return 0;
59}