top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

How to convert numbers into text using C?

+4 votes
83 views

For example if we provide input as 122, then output should be "One hundred and twenty two"

posted Oct 4, 2014 by Kapil Kapoor

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
#include<stdio.h>

int main(){

    int number,i=0,j,digit;
    char * word[1000];

    printf("Enter any integer: ");
    scanf("%d",&number);

    while(number){

    digit = number %10;
    number = number /10;

         switch(digit){
             case 0: word[i++] = "zero"; break;
             case 1: word[i++] = "one"; break;
             case 2: word[i++] = "two"; break;
             case 3: word[i++] = "three"; break;
             case 4: word[i++] = "four"; break;
             case 5: word[i++] = "five"; break;
             case 6: word[i++] = "six"; break;
             case 7: word[i++] = "seven"; break;
             case 8: word[i++] = "eight"; break;
             case 9: word[i++] = "nine"; break;

         }
    }

    for(j=i-1;j>=0;j--){
         printf("%s ",word[j]);
    }

    return 0;

}

Sample output:

Enter any integer: 23451208
two three four five one two zero eight
answer Nov 29, 2014 by Manikandan J
Similar Questions
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...