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

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.