C Program to Print Number of Days in a Month

In this tutorial, i am going to show you how to find and print number of day in a month with the help of if else and switch case statements in c programs.

All C Programs to Print Number of Days in a Month

  • C Program to Print Number of Days in a Month using Switch Case
  • C Program to Print Number of Days in a Month Name using If Else

C Program to Print Number of Days in a Month using Switch Case

#include <stdio.h>
int main()
{
  int month;
  printf(" Please Enter the Month Number 1 to 12 (Consider 1 = January, and 12 = December) :  ");
  scanf("%d", &month);
  
  switch(month )
  {
  	case 1:
  	case 3:
	case 5: 	
	case 7:
	case 8:
	case 10:
	case 12:			  	
	  	printf("\n 31 Days in this Month");
	  	break;
	
	case 4:	
	case 6:
	case 9:
	case 11:			    	
	  	printf("\n 30 Days in this Month");  
		break;
	
	case 2:
	  	printf("\n Either 28 or 29 Days in this Month");  
	
	default:		  	
	    printf("\n Please enter Valid Number between 1 to 12");
  }
  return 0;
}

The result of the above c program; as follows:

 Please Enter the Month Number 1 to 12 (Consider 1 = January, and 12 = December) :  12

 31 Days in this Month

C Program to Print Number of Days in a Month using If Else

/* C Program to Print Number of Days in a Month using Else If Statement */
#include <stdio.h>
int main()
{
  int month;
  printf(" Please Enter the Month Number 1 to 12 (Consider 1 = January, and 12 = December) :  ");
  scanf("%d", &month);
  
  if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 )
  {
  	printf("\n 31 Days in this Month");  	
  }
  else if ( month == 4 || month == 6 || month == 9 || month == 11 )
  {
  	printf("\n 30 Days in this Month");  	
  }  
  else if ( month == 2 )
  {
  	printf("\n Either 28 or 29 Days in this Month");  	
  } 
  else
    printf("\n Please enter Valid Number between 1 to 12");
  
  return 0;
}

The result of the above c program; as follows:

 Please Enter the Month Number 1 to 12 (Consider 1 = January, and 12 = December) :  5

 31 Days in this Month

More C Programming Tutorials

Leave a Comment