Basic Programming C# Examples

C# Program to read any Day Number & Display Day name

The Program in C# Sharp to read any day number in integer and display day name in the word is given below:

using System;

namespace DayName
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Codeauri Family, Enter a number here for a day of the week: ");
            int dayNumber = int.Parse(Console.ReadLine());

            switch (dayNumber)
            {
                case 1:
                    Console.WriteLine("Wow, its Monday");
                    break;
                case 2:
                    Console.WriteLine("Wow, its Tuesday");
                    break;
                case 3:
                    Console.WriteLine("Wow, its Wednesday");
                    break;
                case 4:
                    Console.WriteLine("Wow, its Thursday");
                    break;
                case 5:
                    Console.WriteLine("Wow, its Friday");
                    break;
                case 6:
                    Console.WriteLine("Wow, its Saturday");
                    break;
                case 7:
                    Console.WriteLine("Wow, its Sunday");
                    break;
                default:
                    Console.WriteLine("Invalid day number");
                    break;
            }

            Console.ReadLine();
        }
    }
}

Output:

Hello Codeauri Family, Enter a number here for a day of the week:
7

Wow, its Sunday

Pro-Tips💡

Here are the step by step execution of above program:

  1. The code starts by including the System namespace using the “using System;” statement.
  2. It then defines a namespace called “DayName”.
  3. Within the namespace, it defines a class named “Program”.
  4. The Main method is defined within the Program class. This is the entry point for the program.
  5. The program writes a prompt to the console for the user to enter a day number.
  6. It then reads the user’s input, converts it to an integer using int.Parse, and stores it in the dayNumber variable.
  7. The program uses a switch statement to check the value of the dayNumber variable.
  8. Depending on the value of dayNumber, the program outputs the name of the corresponding day of the week.
  9. If the value of dayNumber is not in the range of 1 to 7, the program outputs an “Invalid day number” message.
  10. The program waits for the user to press enter before ending by using Console.ReadLine().

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X