Programming Examples

C program that takes as input an integer between 1 12 and print corresponding month name


Write a program that takes as input an integer between 1-12 (both inclusive) and prints the month corresponding to that integer.

Solution

#include <stdio.h>
int main() 
{
	int num;
	printf("\nInput a number between 1 to 12 to get the month name: ");
	scanf("%d", &num);
	switch(num) 
	{
		case 1 : printf("January"); 
		break;
		case 2 : printf("February"); 
		break;
		case 3 : printf("March"); 
		break;
		case 4 : printf("April"); 
		break;
		case 5 : printf("May"); 
		break;
		case 6 : printf("June"); 
		break;
		case 7 : printf("July"); 
		break;
		case 8 : printf("August"); 
		break;
		case 9 : printf("September"); 
		break;
		case 10 : printf("October"); 
		break;
		case 11 : printf("November"); 
		break;
		case 12 : printf("December"); 
		break;
		default : printf("Input a number between 1 to 12.");
	}
	return 0;
}
Output

Input a number between 1 to 12 to get the month name: 6

June

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz