w3resource
C# Sharp Programming Exercises

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

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?



New Content: Composer: Dependency manager for PHP, R Programming