# Convert number to word

Write a program to convert number to word

For example:
467
Four hundred sixty seven

2321
Two thousand three hundred twenty one

## Solution:

``````using System;
using System.Text;

namespace Conversion
{
class Program
{
private static readonly string[] X = {
" ", "One ", "Two ", "Three ", "Four ", "Five ", "Six ",
"Seven ", "Eight ", "Nine ", "Ten ", "Eleven ","Twelve ",
"Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ",
"Seventeen ", "Eighteen ", "Nineteen "
};

private static readonly string[] Y = {
" ", " ", "Twenty ", "Thirty ", "Forty ", "Fifty ",
"Sixty ", "Seventy ", "Eighty ", "Ninety "
};

public static void Main()
{
Console.WriteLine("Enter a number");
Console.WriteLine(ConvertNumberToWord(i));
}

private static string ConvertNumberToWord(int n, string suffix)
{
if (n == 0)
return "";

if (n > 19)
return Y[n / 10] + X[n % 10] + suffix;

return X[n] + suffix;
}

public static string ConvertNumberToWord(int n)
{
var stringBuilder = new StringBuilder();
stringBuilder.Append(ConvertNumberToWord(n / 1000000000 % 100, "Billion, "));
stringBuilder.Append(ConvertNumberToWord(n / 10000000 % 100, "Crore, "));
stringBuilder.Append(ConvertNumberToWord(n / 100000 % 100, "Lakh, "));
stringBuilder.Append(ConvertNumberToWord(n / 1000 % 100, "Thousand "));
stringBuilder.Append(ConvertNumberToWord(n / 100 % 10, "Hundred "));

if (n > 100 && n % 100 != 0)
{
stringBuilder.Append("and ");
}
stringBuilder.Append(ConvertNumberToWord(n % 100, ""));

return stringBuilder.ToString();
}

}
}``````