C Program to convert a 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 a number into characters in c.

#include<stdio.h>

int main() {

   int n, rev = 0, r;

   printf("Enter a number:");
   scanf("%d", &n);

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

   n = rev;

   while (n > 0) {
       r = n % 10;
       switch (r) {

           case 0:
               printf("Zero ");
               break;

           case 1:
               printf("One ");
               break;

           case 2:
               printf("Two ");
               break;

           case 3:
               printf("Three ");
               break;

           case 4:
               printf("Four ");
               break;

           case 5:
               printf("Five ");
               break;

           case 6:
               printf("Six ");
               break;

           case 7:
               printf("Seven ");
               break;

           case 8:
               printf("Eight ");
               break;

           case 9:
               printf("Nine ");
               break;
       }
       n = n / 10;
   }

   return 0;
}

Output:

Enter a number:2341                                                                                                                    
Two Three Four One