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.

18 comments:

Anonymous said...

hi mr. kumar i really like your site coz you a have a lot of sample programs that are already ran.
i hope that you could help about this kind of matter coz this my obstacle in studying computer science.

Bheema Palina said...

/**************Program to convert a number into words by BheemaPalina(0-1,00,00,000)***
output:
enter a num:12345(you can enter upto 1crore)
you have entered: twelve thousand three hundred forty five.
*******/
#include
#include
#include
void fun1(int n);
void fun2(int m);
void fun3(int j,int k);
void test1(int n);
void test2(int n);
void test3(int n);
void test4(int n);
int main()
{
int n;
printf("enter a num(1-100,00,000):");
scanf("%d",&n);
printf("\nyou have entered:");
if(n<=100)
test1(n);
else if(n>100&&n<1000)
test2(n);
else if(n>=1000&&n<=100000)
test3(n);
else if(n>100000&&n<=10000000)
test4(n);
return 0;
}

void test1(n)
{
int m,j,k;
if(n>=0&&n<=10)fun1(n);
else if(n>10&&n<20)
{
m=n%10;
fun2(m);
}
else if(n>=20&&n<=100)
{
j=n/10;
k=n%10;
fun3(j,k);
}
}
void test2(int n)
{
int b,c;
c=n/100;
fun1(c);printf(" hundred ");
b=n%100;
test1(b);
}
void test3(int n)
{
int a,b,c;
if(n==1000)
{
printf(" Thousand ");
exit(0);
}
else if(n==100000)
{
printf("Lakh");
exit(0);
}
else{
a=n/1000;
test1(a);printf(" Thousand ");
c=n%1000;
if(c<=99)test1(c);
else test2(c);
}
}
void test4(int n)
{
int a,b;
if(n==10000000)
{
printf("one crore");
exit(0);
}
a=n/100000;
test1(a);printf(" Lakhs ");
b=n%100000;
if(b==0)exit(0);
else if(b<=99)test1(b);
else if(b>99&&b<=999)test2(b);
else test3(b);
}

void fun1(int n)
{
switch(n)
{
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;
case 10:printf("ten");break;
default:printf("");
}
}
void fun2(int m)
{
switch(m)
{
case 1:printf("eleven");break;
case 2:printf("twelve");break;
case 3:printf("thirteen");break;
case 4:printf("fourteen");break;
case 5:printf("fifteen");break;
case 6:printf("sixteen");break;
case 7:printf("seventeen");break;
case 8:printf("eighteen");break;
case 9:printf("nineteen");break;
default:printf("");
}
}
void fun3(int j,int k)
{
switch(j)
{
case 2:printf("twenty ");break;
case 3:printf("thirty ");break;
case 4:printf("fourty ");break;
case 5:printf("fifty ");break;
case 6:printf("sixty ");break;
case 7:printf("seventy ");break;
case 8:printf("eighty ");break;
case 9:printf("ninty ");break;
case 10:printf("hundred");break;
default:printf("");
}
fun1(k);
}

Anonymous said...

nice solution by Bheema

Abhishek Thakur said...

Could you please tell me the header files you have used.

Saurabh Mehta said...

#include
#include

int main()
{
int num;
int temp;
int rev = 0;
int r;

printf("\nEnter a number : ");
scanf("%d",&num);

temp = num;

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

temp = rev;
printf("\n");
while(temp > 0)
{
r = temp % 10;
temp = temp / 10;

switch(r)
{
case 0:
printf("Zero ");
break;
case 1:
printf("One ");
break;
case 2:
printf("Two ");
break;
case 3:
printf("Four ");
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;
}
}

getch();
return 0;
}

Shavon Goulbourne said...

#include


//begginning of function main
int main() {
//declaration
char firstnum,secondnum,thirdnum;
//initialization
firstnum=secondnum=thirdnum=0;
//prompt
printf("enter a number");
scanf("%d%d%d",&firstnum,&secondnum,&thirdnum);


firstnum=0;

switch (firstnum);
{

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;
}
return 0;
}

zohaib qureshi said...

write a program in c++ that convert digit into word like this(11330 == eleven thousand thirty three hundred) and also speak the output means speak the word ... can any one help me plz....

KHLOE5SOS said...

I need a c program that converts word into digit like (one thousand thirty one and sixty nine cents == 1031.69)

I really need it

Tejas Gandre said...

The above program doesn't work integers ending with 0 or beginning with 0

InMusicWeTrust said...

stdio
stdlib
math

InMusicWeTrust said...

stdio
stdlib
math

Yohn Paul said...

isnt there a shorter code executing the same function?

Yohn Paul said...

isnt there a shorter code executing the same function?

Pranav Gurav said...

yes,there is shorter code for this.
which works full efficiently.

Alisha Kapoor said...

Please tell me the solution of this program
Write a ‘C’ program to accept any 3 digit integer number from the keyboard and display the word equivalent representation of the given number.

kaveri tilaganji said...

I NEED ALGORITHM AND FLOWCHART FOR THIS ABOVE PROGRAM ... PLZ HELP ME OUT

Alisha Kapoor said...


Write a ‘C’ functions to arrange the elements of an integer array in such a way that all the negative elements are before the positive elements. The array is passed to it as an argument.
Please tell me the solution of this program

Eugene Julius Caliva said...

How do you answer this while using string? in C