by Dinesh Thakur

The program segment given below uses an switch statement to determine the number of days in a given month (mm). The switch statements to handle the following cases: months having 31 days, months having 30 days, February having either 29 or 28 days.


#include<stdio.h>
void main()
{
        int a;
        clrscr();
        printf("Enter any Month : ");
        scanf("%d",&a);
        switch(a)
          {
               case 1:
                             printf("there are 31 days in Jan ");
                             break;
               case 2:
                             printf ("there are 28 days in Feb");
                             break;
               case 3:
                             printf("there are 31 days in March");
                             break;
               case 4:
                             printf("there are 30 days in April");
                             break;
               case 5:
                             printf(" there are 31 days in May");
                             break;
               case 6:
                             printf("there are 30 days in June");
                             break;
               case 7:
                             printf("there are 31 days in July");
                             break;
               case 8:
                             printf("there are 31 days in August");
                             break;
               case 9:
                             printf("there are 30 days in Sept.");
                             break;
               case 10:
                             printf("there are 31 days in Oct.");
                             break;
               case 11:
                             printf("there are 30 days in Nove.");
                             break;
               case 12:
                             printf("there are 31 days in Dece.");
                             break;
               default:
                             printf("it is not found ");
         }
                             getch();
}
Output :
Enter any Month : 2
there are 28 days in Feb