Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Accept digit and display in the word


C# Sharp Conditional Statement: Exercise-21 with Solution

Write a program in C# Sharp to read any digit, display in the word.

Sample Solution:-

C# Sharp Code:

using System;  
public class Exercise21  
{  
    public static void Main()
{
   int cdigit;

           Console.Write("\n\n");
           Console.Write("Accept digit and display in word:\n");
           Console.Write("-----------------------------------");
           Console.Write("\n\n");


          Console.Write("Input Digit(0-9) : ");
          cdigit = Convert.ToInt32(Console.ReadLine());

   switch(cdigit)
   {
	 case 0:
	      Console.Write("Zero\n");
	       break;
 
	 case 1:
	       Console.Write("one\n");
	       break;
	case 2:
	       Console.Write("Two\n");
	       break;
	case 3:
	       Console.Write("Three\n");
	       break;
	case 4:
	       Console.Write("Four\n");
	       break;
	case 5:
	       Console.Write("Five\n");
	       break;
	case 6:
	       Console.Write("Six\n");
	       break;
	case 7:
	       Console.Write("Seven\n");
	       break;
	case 8:
	       Console.Write("Eight\n");
	       break;
	case 9:
	       Console.Write("Nine\n");
	       break;
	default:
	       Console.Write("invalid digit. \nPlease try again ....\n");
	       break;
      }
  }
}

Sample Output:

Accept digit and display in word:                                                                             
-----------------------------------                                                                   
Input Digit(0-9) : 8                                                                                          
Eight

Pictorial Presentation:

Conditional Statement: Accept digit and display in word.

Flowchart:

Flowchart: Accept digit and display in word.

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C# Sharp to read any day number in integer and display day name in the word.
Next: Write a program in C# Sharp to read any Month Number in integer and display Month name in the word.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.