Write a C program to enter month and print number of days in a month using switch case statement.
How to find the number of days in a month in C.
How to find the number of days in a month in C.
Required Knowledge
In this program, we will take a number between 1 to 12 as input from user, where 1 corresponds to January, 2 corresponds to February and so on. We will use switch case statement to print number of days in any month in words.
C program to print number of days in a month using switch statement
#include <stdio.h> int main() { int month; /* * Take the Month number as input form user */ printf("Enter Month Number (1 = January ..... 12 = December)\n"); scanf("%d", &month); switch(month){ case 2 : printf("28 or 29 Days in Month\n"); break; case 4: case 6: case 9: case 11: printf("30 Days in Month\n"); break; case 1: case 3: case 5: case 7: case 8: case 10: case 12: printf("31 Days in Month\n"); break; default : printf("Invalid Input !!!!"); } return 0; }Output