Saturday, 2 December 2017

C# Program to Convert Digits to Words


Code:

using System; 

public class ConvertDigitsToWords
{   
  public static void Main()
  { 
    int num; 
    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");
    num = Convert.ToInt32(Console.ReadLine());
    Console.WriteLine("Number: " + num); 
    Console.Write("Number in words: ");    
    nextdigit = 0; 
    numdigits = 0; 
    do 
    { 
      nextdigit = num % 10; 
      n[numdigits] = nextdigit; 
      numdigits++; 
      num = num / 10; 
    } while(num > 0); 
    numdigits--; 
    for( ; numdigits >= 0; numdigits--) 
        Console.Write(digits[n[numdigits]] + " "); 
    Console.WriteLine();
    Console.ReadLine();
  }   
}


Output:

Enter the number
1548
Number: 1548
Number in words: one five four eight


More C# Programs:


















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...