In this post we will use switch statement to print the number of days in a month. So we have given the full code for it and output.
Code for c program to print the number of days in a month using switch statements
#include<stdio.h>
#include<conio.h>
int main()
{
int month;
printf(" Please Enter the Month number 1 to 12: ");
scanf("%d", &month);
switch(month)
{
case 2:
printf("28/29 days");
break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
printf("31 days");
break;
case 4:
case 6:
case 9:
case 11:
printf("30 days");
break;
default:
printf("Invalid input! Please enter month number between 1-12");
}
return 0;
}
Output
Please Enter the Month number 1 to 12: 9
30 days
Read: C program to find the maximum of two numbers using switch statement