29 December, 2012

C++ Program For Conversion Of Integers/Numbers Into Words.

This Post Contains A C++ Program For Conversion Of Integers/Numbers Into Words With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'Arrays', 'If...else' & 'For-Loop' From C++ Language. It Is A Well-Structured Program With Proper Comments Which Provides Step-By-Step Description Of Various Features Of The Language In A Simple & Easy-To-Understand Way.

# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.


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

Subscribe To:

Most Commonly Asked Programs In 'C' & 'C++' Language.