Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#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:

Enter month number(1-12): 8

31 days

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write C program to print day of week name using sw... >>