C# Program to Convert Digits to Words.

Aim :- C# Program to Convert Digits to Words.

C# Code :

                            
using System;
namespace Practical1_5
{    
   class Program
   {
      static void Main(string[] args)
      {
         int num;
         int nextdigit;
         int numdigits;
         int[] n = new int[20];
         string[] digits = {"ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE" };
         Console.Write("Enter The Number : ");
         num = Convert.ToInt32(Console.ReadLine());
         Console.WriteLine("Entered Number : " + num);
         Console.Write("Digit 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:

Post a Comment

0 Comments