C++ Program to Convert Number into Characters


In this Program, You will learn How to Convert Number into Characters in C++.


123 => One Two Three


Example: How to Convert Number into Characters in C++

Run it Now
#include<iostream>
using namespace std;

int main() {

   int n, rev = 0, r;

   cout << "Enter a Number :";
   cin>>n;

   while (n > 0) {
       r = n % 10;
       rev = rev * 10 + r;
       n = n / 10;
   }
   n = rev;
   cout << "\n";

   while (n > 0) {
       r = n % 10;
       switch (r) {
           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;
       }
       n = n / 10;
   }

   return 0;
}
 

Output:

Enter a Number :420035
Four Two Zero Zero Three Five