Write C program to print number of days in a month using switch case


Introduction

Write C program to print number of days in a month using switch case


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>

int main()
{
    int monthnumber;

    //Reading a month number from user

    printf("Enter month number(1-12): ");
    scanf("%d", &monthnumber);

    switch(monthnumber)
    {
        case 1: printf("31 days");
            break;
        case 2: printf("28 or 29 days");
            break;
        case 3: printf("31 days");
            break;
        case 4: printf("30 days");
            break;
        case 5: printf("31 days");
            break;
        case 6: printf("30 days");
            break;
        case 7: printf("31 days");
            break;
        case 8: printf("31 days");
            break;
        case 9: printf("30 days");
            break;
        case 10: printf("31 days");
            break;
        case 11: printf("30 days");
            break;
        case 12: printf("31 days");
            break;
        default: printf("Invalid input!!! enter month number between 1-12");

    }

    return 0;
}

Result

C language

     





Related Topics




Popular Posts