C Program to Print Number of Days in a Month

C Program to Print Number of Days in a Month

C program to print a number of days in a month; Through this tutorial, we will learn how to find and print number of day in a month using if else and switch case statements in c programs.

Programs to Print Number of Days in a Month in C

  • 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 output 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 output 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

Recommended C Programs

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published.