Convert Number in Characters in C++

Share on facebook
Share on twitter
Share on linkedin
Share on twitter
Share on tumblr

In this Basic C++ Program, we will have a look at the C++ Program to write a c++ program to convert the number in characters.

In C ++, we can easily convert the number of characters using a loop and switch. In this program, we collect data from the user and repeat this number until it reaches 0.

During iteration, divide it by 10, and transfer the rest in the switching box to get the word for the number.

Convert Number in Characters in C++

#include <iostream>  
using namespace std;  
int main()  

long int n,sum=0,r;    
cout<<"Enter the Number= ";    
cin>>n;    
while(n>0)    
{    
r=n%10;    
sum=sum*10+r;    
n=n/10;    
}    
n=sum;    
while(n>0)    
{    
r=n%10;    
switch(r)    
{    
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;    
case 0:    
cout<<"zero ";  
break;    
default:    
cout<<"tttt ";    
break;    
}    
n=n/10;    
}    

Output:

Enter the Number= 74254
seven four two five four

Leave a Comment

Your email address will not be published. Required fields are marked *