convert numbers less than 10 billion to words
I tried running the answer in the previous thread on visual c# but it was given an incorrect answer,I don't know why.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pankaj Kumar ChoudharyPosted Mar 7, 2015, 11:55 AM
Code is:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
void Convert(long num, string str)
{
string[] st ={" "," one"," two"," three"," four"," five"," six"," seven"," eight"," nine", " ten",
" eleven"," twelve"," thirteen"," fourteen"," fifteen"," sixteen"," seventeen"," eighteen"," ninteen"};
string[] st2 ={" "," "," twenty"," thirty"," fourty"," fifty"," sixty",
" seventy"," eighty"," ninty"};
if (num > 19)
Console.Write(" {0} {1} ", st2[num / 10], st[num % 10]);
else
Console.Write("{0} ", st[num]);
if (num != 0)
Console.Write("{0} ", str);
}
static void Main(string[] args)
{
long n;
Program pg = new Program();
Console.WriteLine("Enter Your Number ");
n = long.Parse(Console.ReadLine());
if (n < 0)
Console.WriteLine("Number Should be greater then 0");
else
{
pg.Convert((n / 10000000), "crore");
pg.Convert(((n / 100000) % 100), "lakh");
pg.Convert(((n / 1000) % 100), "thousand");
pg.Convert(((n / 100) % 10), "hundred");
pg.Convert((n % 100), " ");
}
Console.ReadKey();
}
}
}