C program to find number of days in a month

C program to find number of days in a month

  • This is a simple program to get number of days in a month.
  • Leap year is not being chacked in the program.
  • This program uses switch case.
number-of-days-of-a-month
number-of-days-of-a-month

#include <stdio.h>

int main()

{

int month;
int days;

printf(“Enter month: “);
scanf(“%d”,&month);

switch(month)

{

case 4:

case 6:

case 9:

case 11:

days=30;

break;

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

days=31;

break;

case 2:

days=28;

break;

default:

days=0;

break;

}

if(days)
printf(“Number of days in %d month is: %d\n”,month,days);
else
printf(“This is not a vaild month\n”);
return 0;

}

Output:


Enter month: 5
Number of days in 5 month is: 31


Enter month: 2

Number of days in 2 month is: 28


Enter month: 4
Number of days in 4 month is: 30


Enter month: 13
This is not a vaild month

 

[xyz-ihs snippet=”Discuss”]

Leave a Reply