Basic Programming C# Examples

C# Program to Read any Digit & Display in Word

The Program in C# Sharp to read any digit, display in the word is given below:

using System;

namespace DigitToWord
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Codeauri Family,enter a digit to display in word below: ");
            char digit = Console.ReadLine()[0];

            switch (digit)
            {
                case '0':
                    Console.WriteLine("Zero");
                    break;
                case '1':
                    Console.WriteLine("One");
                    break;
                case '2':
                    Console.WriteLine("Two");
                    break;
                case '3':
                    Console.WriteLine("Three");
                    break;
                case '4':
                    Console.WriteLine("Four");
                    break;
                case '5':
                    Console.WriteLine("Five");
                    break;
                case '6':
                    Console.WriteLine("Six");
                    break;
                case '7':
                    Console.WriteLine("Seven");
                    break;
                case '8':
                    Console.WriteLine("Eight");
                    break;
                case '9':
                    Console.WriteLine("Nine");
                    break;
                default:
                    Console.WriteLine("Invalid digit");
                    break;
            }

            Console.ReadLine();
        }
    }
}

Output:

Hello Codeauri Family,enter a digit to display in word below:
9
Nine

Pro-Tips💡

Here are the step by step execution of above program:

  1. The program includes the System namespace, which is necessary for using the Console class to input and output data.
  2. The program defines a namespace DigitToWord and a class Program within the namespace.
  3. The Main method is defined within the class, which is the entry point of the program.
  4. The program outputs a message “Hello Codeauri Family, enter a digit to display in word below: ” using the Console.WriteLine method.
  5. The program takes a single digit character input from the user using the Console.ReadLine method and converts the input string to a character by accessing the first character of the string using the indexer [0].
  6. The program uses a switch statement to match the digit character input with a case label for each digit and outputs the corresponding word representation of the digit using the Console.WriteLine method.
  7. If the input digit does not match any of the case labels, the default case is executed, which outputs the message “Invalid digit”.
  8. The program pauses to wait for user input before closing the console window using the Console.ReadLine method.

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