Header Ads Widget

Ticker

6/recent/ticker-posts

C++ Program to Convert Number in Characters coding by Digitalise Data

C++ Program to Convert Number in Characters coding by Digitalise Data

 C++ Program to Convert Number in Characters

In C++ language, we can easily convert number in characters by the help of loop and switch case. In this program, we are taking input from the user and iterating this number until it is 0. While iteration, we are dividing it by 10 and the remainder is passed in switch case to get the word for the number.

Let's see the C++ program to convert number in characters.

  1. #include <iostream.h>
  2. #include <conio.h>
  3. void main()  
  4. {  
  5. long int n,sum=0,r;    
  6. cout<<"Enter the Number= ";    
  7. cin>>n;    
  8. while(n>0)    
  9. {    
  10. r=n%10;    
  11. sum=sum*10+r;    
  12. n=n/10;    
  13. }    
  14. n=sum;    
  15. while(n>0)    
  16. {    
  17. r=n%10;    
  18. switch(r)    
  19. {    
  20. case 1:    
  21. cout<<"one ";    
  22. break;    
  23. case 2:    
  24. cout<<"two ";    
  25. break;    
  26. case 3:    
  27. cout<<"three ";  
  28. break;    
  29. case 4:    
  30. cout<<"four ";  
  31. break;    
  32. case 5:    
  33. cout<<"five ";  
  34. break;    
  35. case 6:    
  36. cout<<"six ";   
  37. break;    
  38. case 7:  
  39. cout<<"seven ";  
  40. break;  
  41. case 8:    
  42. cout<<"eight ";    
  43. break;    
  44. case 9:    
  45. cout<<"nine ";  
  46. break;    
  47. case 0:    
  48. cout<<"zero ";  
  49. break;    
  50. default:    
  51. cout<<"tttt ";    
  52. break;    
  53. }    
  54. n=n/10;    
  55. }    
  56. getch();
  57. }  

Output:

Enter the Number= 74254
seven four two five four

Post a Comment

0 Comments