adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C++ to print given number into word

Program in C++  to print given number into word



#include<iostream>
#include<conio.h>
 using namespace std;
 int main()
  {
   int n;
   char num[21][12]={" ","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven"
   ,"Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
     cout<<"Enter a any one  number between 1 to 100:-";
     cin>>n;
     if(n>=1&&n<20)
       cout<<num[n];
      else
        {
         switch(n/10)
          {
             case 2:n=n%10;
                    cout<<"Twenty "<<num[n];
                    break;
             case 3:n=n%10;
                    cout<<"Thirty "<<num[n];
                    break;
             case 4:n=n%10;
                    cout<<"Forty "<<num[n];
                    break;
             case 5:n=n%10;
                    cout<<"Fifty "<<num[n];
                    break;
             case 6:n=n%10;
                    cout<<"Sixty "<<num[n];
                    break;
             case 7:n=n%10;
                    cout<<"Seventy "<<num[n];
                    break;
             case 8:n=n%10;
                    cout<<"Eighty "<<num[n];
                    break;
             case 9:n=n%10;
                    cout<<"Ninety "<<num[n];
                    break;
             case 10:cout<<"One Hundred";
                     break;
            }
         }
     getch();
    return 0;
  }
Output:-













Post a Comment

0 Comments