Program to read any day number in integer and display the day name in word format.

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

Code to print the name of the day in C language

#include <stdio.h>
void main()
{
   int dayno;
   printf("Input Day No : ");
   scanf("%d",&dayno);
   switch(dayno)
   {
	case 1:
	       printf("Monday \n");
	       break;
	case 2:
	       printf("Tuesday \n");
	       break;
	case 3:
	       printf("Wednesday \n");
	       break;
	case 4:
	       printf("Thursday \n");
	       break;
	case 5:
	       printf("Friday \n");
	       break;
	case 6:
	       printf("Saturday \n");
	       break;
	case 7:
	       printf("Sunday  \n");
	       break;
	default:
	       printf("Invalid day number. \nPlease try again ....\n");
	       break;
      }
}

Code to print the name of the day in C++ language

#include<iostream>
using namespace std;
int main()
{
   int dayno;
   cout<<"Input Day No : ";
   cin>>dayno;
   switch(dayno)
   {
	case 1:
	       cout<<"Monday \n";
	       break;
	case 2:
	       cout<<"Tuesday \n";
	       break;
	case 3:
	       cout<<"Wednesday \n";
	       break;
	case 4:
	       cout<<"Thursday \n";
	       break;
	case 5:
	       cout<<"Friday \n";
	       break;
	case 6:
	       cout<<"Saturday \n";
	       break;
	case 7:
	       cout<<"Sunday  \n";
	       break;
	default:
	       cout<<"Invalid day number. \nPlease try again ....\n";
	       break;
      }
}

Code to print the name of the day in Python language

dayno=int(input("Input Day No :  "))
if(dayno == 1):
    print("Monday")
elif(dayno == 2):
    print("Tuesday")
elif(dayno == 3):
    print("Wednesday")
elif(dayno == 4):
    print("Thursday")
elif(dayno == 5):
    print("Friday")
elif(dayno == 6):
    print("Saturday")
elif(dayno == 7):
    print("Sunday")
else:
    print("Invalid day number. \nPlease try again ....\n")

Code to print the name of the day in Java language

import java.util.*;
public class dayOfWeek {

    public static void main(String[] args) {

        int dayno;

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

             switch(dayno)
               {
		case 1:
		       System.out.println("Monday ");
		       break;
		case 2:
		      System.out.println("Tuesday ");
		       break;
		case 3:
		       System.out.println("Wednesday ");
		       break;
		case 4:
		      System.out.println("Thursday ");
		       break;
		case 5:
		      System.out.println("Friday ");
		       break;
		case 6:
		       System.out.println("Saturday ");
		       break;
		case 7:
		       System.out.println("Sunday ");
		       break;
		default:
		       System.out.println("Invalid day number. Please try again ....");
		       break;
                 }

    }
}