w3resource
C# Sharp Programming Exercises

C# Sharp Exercises: Accept day number and display its equivalent day name in the word


C# Sharp Conditional Statement: Exercise-20 with Solution

Write a program in C# Sharp to read any day number in integer and display day name in the word.

Sample Solution:-

C# Sharp Code:

using System;  
public class Exercise20  
{  
    public static void Main()
{
   int dayno;

           Console.Write("\n\n");
           Console.Write("Accept day number and display its equivalent day name in word:\n");
           Console.Write("----------------------------------------------------------------");
           Console.Write("\n\n");


   Console.Write("Input Day No : ");
   dayno = Convert.ToInt32(Console.ReadLine());

   switch(dayno)
   {
	case 1:
	       Console.Write("Monday \n");
	       break;
	case 2:
	       Console.Write("Tuesday \n");
	       break;
	case 3:
	       Console.Write("Wednesday \n");
	       break;
	case 4:
	       Console.Write("Thursday \n");
	       break;
	case 5:
	       Console.Write("Friday \n");
	       break;
	case 6:
	       Console.Write("Saturday \n");
	       break;
	case 7:
	       Console.Write("Sunday  \n");
	       break;
	default:
	       Console.Write("Invalid day number. \nPlease try again ....\n");
	       break;
      }
   }
}

Sample Output:

Accept day number and display its equivalent day name in word:                                                
----------------------------------------------------------------                                              
                                                                                  
Input Day No : 5                                                                                              
Friday 

Flowchart:

Flowchart: Accept day number and display its equivalent day name in word

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C# Sharp to accept a grade and display the equivalent description.
Next: Write a program in C# Sharp to read any digit, display in the word.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming