C# Program to convert a number into characters


In this program, You will learn how to convert a number into characters in C#.


123 => One Two Three

Example: How to convert a number into characters in C#.

using System;
public class Program
{
	public static void Main(string[] args)
	{
		int n, rev = 0, r;
		Console.Write("Enter a number:");
		n = Convert.ToInt32(Console.ReadLine());
		Console.Write("Characters is:");

		while (n > 0)
		{
			r = n % 10;
			rev = rev * 10 + r;
			n = n / 10;
		}
		n = rev;

		while (n > 0)
		{
			r = n % 10;
			switch (r)
			{
				case 0:
					Console.Write("Zero ");
					break;

				case 1:
					Console.Write("One ");
					break;

				case 2:
					Console.Write("Two ");
					break;

				case 3:
					Console.Write("Three ");
					break;

				case 4:
					Console.Write("Four ");
					break;

				case 5:
					Console.Write("Five ");
					break;

				case 6:
					Console.Write("Six ");
					break;

				case 7:
					Console.Write("Seven ");
					break;

				case 8:
					Console.Write("Eight ");
					break;

				case 9:
					Console.Write("Nine ");
					break;
			}
			n = n / 10;
		}
	}
}

Output:

Enter a number:40309
Characters is:Four Zero Three Zero Nine