# C# Program to Convert Digits to Words

«
»

This is a C# Program to convert digits to words.

Problem Description

This C# Program Converts Digits to Words.

Problem Solution

Here the user enters the number which is again converted and diplayed in terms of words with the help of a mod function.

Program/Source Code

Here is source code of the C# Program to Convert Digits to Words. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

```/*
*  C# Program to Convert Digits to Words
*/
using System;

public class ConvertDigitsToWords
{
public static void Main()
{
int num;
int nextdigit;
int numdigits;
int[] n = new int;

string[] digits = { "zero", "one", "two",
"three", "four", "five",
"six", "seven", "eight",
"nine" };

Console.WriteLine("Enter the number");
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();
}
}```
Program Explanation

This C# program, we are reading the number using ‘num’ variable. Using do while loop Compute the modulus of the value of ‘num’ variable by 10. Assign the resulted value to ‘nextdigit’ variable and increment the value of ‘numdigit’ variable.

Note: Join free Sanfoundry classes at Telegram or Youtube

Compute the value of ‘num’ variable by 10. While loop is used to check the value of ‘num’ variable is greater than 0. If the condition is true, then execute the iteration of the loop. For loop is used to convert the digits to words and print the output of the program.

Runtime Test Cases
```
Enter the number
1548
Number: 1548
Number in words: one five four eight```

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs. 