Wednesday, September 9, 2009

Number to Text in console Program



namespace Number2Text01
{
class Program
{
static string str;
static void Main(string[] args)
{
Console.Write("\n Enter Three Digit number::");
int amt = int.Parse(Console.ReadLine());
int temp,i;
//static string str;
string[] Hundreds = new string[] { "One Hundred", "Two hundred", "Three Hundreds", "Four Hundreds", "Five hundred", "Six hundred", "Seven Hundreds", "Eight hundred", "Nine hundred" };
string[] Tens = new string[] { "", "Ten", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eight", "Ninty" };
string[] Ones = new string[] {"","One","Two","Three","Four","Five","Six","Seven","Eight","Nine" };

int[] arr = new int[3];
temp=amt;
i = 0;
while (temp != 0)
{
arr[i] = (temp % 10);
temp = temp / 10;
i++;
}
i -= 1;
while (i != -1)
{
if (i == 2)
str = Hundreds[arr[i]-1];
if (i == 1)
str += " and " + Tens[arr[i]];
if (i == 0)
str +=" " + Ones[arr[i]];
i--;
}
Console.WriteLine("\n\t Given number is "+amt+" and the Text is "+str);
Console.Read();
}
}
}

No comments:

Post a Comment

Followers