
C++ Program For Conversion Of Integers/Numbers Into Words.
# include < iostream.h >
# include < conio.h >
void main ()
{
char a[10][10] = { "One" , "Two" , "Three" , "Four" , "Five" , "Six" , "Seven" , "Eight" ,
"Nine" , "Ten" };
char b[10][13] = { "Eleven" , "Twelve" , "Thirteen" , "Fourteen" , "Fifteen" , "Sixteen" ,
"Seventeen" , "Eighteen" , "Nineteen" };
char c[10][10] = { "Ten" , "Twenty" , "Thirty" , "Forty" , "Fifty" , "Sixty" , "Seventy" ,
"Eightty" , "Ninty" , "Hundred" };
int r , s, t;
long n;
clrscr();
/* Enter Any No. Below 1 Lakh */
cout << " Enter Any Number :- ";
cin >> n;
if ( n > 9999 )
{
r = n / 1000;
if ( r > 10 && r < 20 )
{
r = r % 10;
cout << b[ r-1 ] << " Thousands ";
}
else
{
s = r / 10;
t = r % 10;
cout << c[ s - 1 ];
cout << a[ t - 1 ] << " Thousand ";
}
n = n % 1000;
}
if ( n > 1000 )
{
r = n / 1000;
cout << a[ r - 1 ] << " Thousand ";
n = n % 1000;
}
if ( n > 100 )
{
r = n / 100;
cout << a[ r - 1 ] << " Thousand ";
n = n % 100;
}
if ( n > 10 && n < 20 )
{
r = n % 10;
cout << b[ r - 1 ];
}
if ( n > 19 && n <= 100 )
{
r = n / 10;
cout << c[ r - 1 ];
n = n % 10;
}
if ( n > 0 && n <= 10 )
{
cout << a[ n - 1 ];
}
getch();
}
Output :
/* Enter Any No. Below 1 Lakh */
Enter Any Number :- 1234
One Thousand Two Hundred Thirty Four
Enter Any Number :- 111
One Hundred Eleven
No comments:
Post a Comment