//A program to convert Number into Words
// Works Upto 9 Billion ...
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
char d1[][10]={" ","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen",};
char d2[][10]={" ", "Ten","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"};
char d3[][15]={"","Hundred and","Thousand and","Lakh and","Million and","Billion and"};
void test(long int);
void ten(long int);
void hun(long int);
void thou(long int);
void lakh(long int);
void mill(long int);
void bill(long int);
void main()
{
long int num;
cout<<"Enter the Number to be turned into Words : \n";
cout<<"Remember Do Not Enter Zero at front\nbecause C++ shall treat it as Octal No.\n\n\n\t\t\tThe Number\t:";
scanf("%ld",&num);
cout<<"\nIn Words :\n";
if (num<0)
{
cout<<"Minus ";
num=-num;
}
test(num);
getch();
}
void test(long int num)
{
long int copy=num;
if (num<20)
ten(copy);
if (num>=20 && num <=99)
ten(copy);
if (num>=100 && num <=999)
hun(copy);
if (num>=1000 && num<100000)
thou(copy);
if (num>=100000 && num<=9999999)
lakh(num);
if (num>=10000000 && num<=999999999)
mill(num);
if (num>=1000000000)
bill(num);
}
void ten(long int copy)
{
if (copy>=0 && copy <20)
cout<<d1[copy]<<" ";
else
cout<<d2[copy/10]<<" "<<d1[copy%10]<<" ";
return;
}
void hun(long int copy)
{
cout<<d1[copy/100]<<" "<<d3[1]<<" ";
test(copy%100);
return;
}
void thou(long int copy)
{
test(copy/1000);
cout<<d3[2]<<" ";
test(copy%1000);
return;
}
void lakh(long int copy)
{
test(copy/100000);
cout<<d3[3]<<" ";
test(copy%100000);
return;
}
void mill(long int copy)
{
test(copy/10000000);
cout<<d3[4]<<" ";
test(copy%10000000);
return;
}
void bill(long int copy)
{
test(copy/1000000000);
cout<<d3[5]<<" ";
test(copy%1000000000);
return;
}