Dremendo Tag Line

Input number and print the corresponding month name using switch case in C

switch case - Question 1

In this question, we will see how to input an integer between 1 to 12 and print the corresponding name of month in C programming using the switch case statement. To know more about switch case statement click on the switch case statement lesson.

Q1) Write a program in C to input an integer between 1 to 12 and print the corresponding name of month using the switch case statement.

Program

#include <stdio.h>
#include <conio.h>

int main()
{
    int n;
    printf("Enter a number between 1 to 12 : ");
    scanf("%d",&n);
    switch(n)
    {
        case 1:
            printf("January");
            break;

        case 2:
            printf("February");
            break;

        case 3:
            printf("March");
            break;

        case 4:
            printf("April");
            break;

        case 5:
            printf("May");
            break;

        case 6:
            printf("June");
            break;

        case 7:
            printf("July");
            break;

        case 8:
            printf("August");
            break;

        case 9:
            printf("September");
            break;

        case 10:
            printf("October");
            break;

        case 11:
            printf("November");
            break;

        case 12:
            printf("December");
            break;

        default:
            printf("Invalid Input");
    }
    return 0;
}

Output

Enter a number between 1 to 12 : 8
August
video-poster