Program for reading any Month Number and displaying the Month name as a word.

Here, we have a basic program example to print month name corresponding to the number entered by user using different languages. This program is created in c language, c++, Java, and Python.

Code to print month name in C language

#include <stdio.h>
void main()
{
   int monno;
   printf("Input Month No : ");
   scanf("%d",&monno);
   switch(monno)
   {
	case 1:
	       printf("January \n");
	       break;
	case 2:
	       printf("February \n");
	       break;
	case 3:
	       printf("March \n");
	       break;
	case 4:
	       printf("April \n");
	       break;
	case 5:
	       printf("May \n");
	       break;
	case 6:
	       printf("June \n");
	       break;
	case 7:
	       printf("July  \n");
	       break;
    case 8:
	       printf("August \n");
	       break;
	case 9:
	       printf("September \n");
	       break;
	case 10:
	       printf("October \n");
	       break;
	case 11:
	       printf("November \n");
	       break;
	case 12:
	       printf("December \n");
	       break;
	default:
	       printf("Invalid month number. \nPlease try again ....\n");
	       break;
      }
}

Code to print month name in C++ language

#include<iostream>
using namespace std;
int main()
{
   int monno;
   cout<<"Input motnh No : ";
   cin>>monno;
   switch(monno)
   {
	case 1:
	       cout<<"January \n";
	       break;
	case 2:
	       cout<<"February \n";
	       break;
	case 3:
	       cout<<"March \n";
	       break;
	case 4:
	       cout<<"April \n";
	       break;
	case 5:
	       cout<<"May \n";
	       break;
	case 6:
	       cout<<"June \n";
	       break;
	case 7:
	       cout<<"July  \n";
	       break;
    case 8:
	       cout<<"August  \n";
	       break;
    case 9:
	       cout<<"September  \n";
	       break;
    case 10:
	       cout<<"October \n";
	       break;
    case 11:
	       cout<<"November \n";
	       break;
    case 12:
	       cout<<"December \n";
	       break;
	default:
	       cout<<"Invalid month number. \nPlease try again ....\n";
	       break;
      }
}

Code to print month name in Python language

monno=int(input("Input Month No :  "))
if(monno == 1):
    print("January")
elif(monno == 2):
    print("February")
elif(monno == 3):
    print("March")
elif(monno == 4):
    print("April")
elif(monno == 5):
    print("May")
elif(monno == 6):
    print("June")
elif(monno == 7):
    print("July")
elif(monno == 8):
    print("August")
elif(monno == 9):
    print("September")
elif(monno == 10):
    print("October")
elif(monno == 11):
    print("November")
elif(monno == 12):
    print("December")
else:
    print("Invalid Month number. \nPlease try again ....\n")

Code to print month name in Java language

import java.util.*;
public class month {

    public static void main(String[] args) {

        int monno;

	   Scanner s=new Scanner(System.in);
	   System.out.println("Input Month No :");
	   monno = s.nextInt();

             switch(monno)
               {
		case 1:
		       System.out.println("January");
		       break;
		case 2:
		      System.out.println("February");
		       break;
		case 3:
		       System.out.println("March ");
		       break;
		case 4:
		      System.out.println("April ");
		       break;
		case 5:
		      System.out.println("May ");
		       break;
		case 6:
		       System.out.println("June ");
		       break;
		case 7:
		       System.out.println("July ");
		       break;
          case 8:
		       System.out.println("August ");
		       break;
          case 9:
		       System.out.println("September ");
		       break;
          case 10:
		       System.out.println("October");
		       break;
          case 11:
		       System.out.println("November");
		       break;
          case 12:
		       System.out.println("December");
		       break;
		default:
		       System.out.println("Invalid month number. Please try again ....");
		       break;
                 }
    }
}