In this post, we will writa a C# Program to Convert Digits to Words.
C# Code: C# Program to convert Digits to Words
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
class Program { public static void Main() { int number; int nextDigit; int numDigits; int[] n = new int[20]; string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; Console.WriteLine("Enter the number"); number = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Number: " + number); Console.Write("Number in words: "); nextDigit = 0; numDigits = 0; do { nextDigit = number % 10; n[numDigits] = nextDigit; numDigits++; number = number / 10; } while (number > 0); numDigits--; for (; numDigits >= 0; numDigits--) Console.Write(digits[n[numDigits]] + " "); Console.WriteLine(); Console.ReadLine(); } } |
Output: