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

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to input weekday number 
// print the weekday
using 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;
               
            }
   
               
        }
    }
}

chevron_right


Output: When we enter number between (0-6).

Enter weekday number (0-6): It is WEDNESDAY

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to input weekday number 
// print the weekday
using 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;
            }
   
               
        }
    }
}

chevron_right


Output: When we enter number beyond the range from (0-6).

Enter weekday number (0-6): It is wrong input



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.