Program to Input Weekday Number and Print the Weekday in C# - GeeksforGeeks

22 Jun, 2020
C# Program to print weekday name from a given weekday number (0-6). A switch statement allows checking a value with a list of values or cases.
Weekday number is the number whose value from 0 to 6. 0 is for “Sunday”, 1 is for “Monday”, 2 is for “Tuesday”, 3 is for “Wednesday”, 4 is for “Thursday”, 5 is for “Friday” and 6 is for “Saturday”. This will check with a switch statement.
Example:
Input: 2

Output: Tuesday

Input: 6

Output: Saturday 

Example 1:
// C# program to input weekday number // print the weekdayusing System;using System.IO;using System.Text;   namespace Geeks{    class GFG    {        // Main Method         static void Main(string[] args)        {            int weekday;               // input weekday number            Console.Write("Enter weekday number (0-6): ");            weekday = Convert.ToInt32(Console.ReadLine());               // Using switch case to validate            switch (weekday)            {                case 0:                    Console.WriteLine("It is SUNDAY");                    break;                case 1:                    Console.WriteLine("It is MONDAY");                    break;                case 2:                    Console.WriteLine("It is TUESDAY");                    break;                case 3:                    Console.WriteLine("It is WEDNESDAY");                    break;                case 4:                    Console.WriteLine("It is THURSDAY");                    break;                case 5:                    Console.WriteLine("It is FRIDAY");                    break;                case 6:                    Console.WriteLine("It is SATURDAY");                    break;                           }                          }    }}
Output: When we enter number between (0-6).
Enter weekday number (0-6): It is WEDNESDAY
Example 2:
// C# program to input weekday number // print the weekdayusing System;using System.IO;using System.Text;   namespace Geeks{    class GFG    {        // Main Method         static void Main(string[] args)        {            int weekday;               // input weekday number            Console.Write("Enter weekday number (0-6): ");            weekday = Convert.ToInt32(Console.ReadLine());               // Using switch case to validate            switch (weekday)            {                case 0:                    Console.WriteLine("It is SUNDAY");                    break;                case 1:                    Console.WriteLine("It is MONDAY");                    break;                case 2:                    Console.WriteLine("It is TUESDAY");                    break;                case 3:                    Console.WriteLine("It is WEDNESDAY");                    break;                case 4:                    Console.WriteLine("It is THURSDAY");                    break;                case 5:                    Console.WriteLine("It is FRIDAY");                    break;                case 6:                    Console.WriteLine("It is SATURDAY");                    break;                                   // if no case value is matched                default:                    Console.WriteLine("It is wrong input");                    break;            }                          }    }}
Output: When we enter number beyond the range from (0-6).
Enter weekday number (0-6): It is wrong input
C#
C# Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Top 50 C# Interview Questions & Answers
Extension Method in C#
HashSet in C# with Examples
Partial Classes in C#
C# | Inheritance
Convert String to Character Array in C#
Getting a Month Name Using Month Number in C#
Socket Programming in C#
Program to Print a New Line in C#
Program to find absolute value of a given number