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

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *