Skip to content
Related Articles

Related Articles

Improve Article

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

  • Last Updated : 22 Jun, 2020
Geek Week

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 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;
               
            }
   
               
        }
    }
}

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 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;
            }
   
               
        }
    }
}

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
Recommended Articles
Page :