Print the digits of a number in words using C++



Write a Program in
C++ to print the digits of a number in words.











Program:





#include <iostream.h>


#include <conio.h>








 class PNIW


  {


   public:


     void
ntow(int);


     void
display(int);


  };





 void PNIW ::
ntow(int n)


   {


    int
i=0,j=0,temp,sum=0,count=0,ar[10];


    temp=n;


   
while(temp!=0)


     {


     
i=temp%10;


     
ar[count]=i;


      count++;


     
temp=temp/10;


     }


   
for(i=count-1;i>=0;i--)


     {


      j=ar[i];


     
display(j);


     }


   }








 void PNIW ::
display(int i)


   {


    switch(i)


    {


    case
0:cout<<"Zero ";


        break;


    case
1:cout<<"One ";


        break;


    case
2:cout<<"Two ";


        break;


    case
3:cout<<"Three ";


        break;


    case
4:cout<<"Four ";


        break;


    case
5:cout<<"Five ";


        break;


    case
6:cout<<"Six ";


        break;


    case
7:cout<<"Seven ";


        break;


    case
8:cout<<"Eight ";


        break;


    case
9:cout<<"Nine ";


        break;


    default:
cout<<"Error ";


          break;


    }


 }








 int main()


  {


  int num;


  clrscr();


 
cout<<"Enter Number: ";


 
cin>>num;


  PNIW ob;


 
ob.ntow(num);





  getch();


  return 0;


  }








Output:


Enter Number: 990




Nine Nine Zero


Comments

Popular posts from this blog

Write a Program to Add two 3x3 Matrix using C

C program for Unit Conversion

Write a Program to Add two 5x5 Matrix using C