C program to convert digits to words





C code to covert each digits of a number in English word

Convert digits to words in c

#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





6. Write a c program to convert octal number to hexadecimal number.
8. Write a c program to convert hexadecimal number to octal number.
9. Write a c program to convert hexadecimal number to decimal number.
10. Write a c program to convert binary number to octal number.
Post a Comment