GoHacking.com: Ethical Hacking and Cyber Security
Home » C PROGRAMMING

C Program to Print the Entered Number in Words

Submitted by on Tuesday, 4 December 20077 Comments

The following C program print’s the entered number in words. For example if the number entered is 12345 then the program prints the entered number in words as One Two Three Four Five

 
#include<stdio.h>
void main()
{
int i=0;
unsigned long int digit;
char str[12],ch;
puts(“Enter the number (less than 10 digit)”);
scanf(“%lu”,&digit);
ultoa(digit,str,10); /*converts an unsigned long int to string*/
while(str[i]!=’\0′)
{
ch=str[i];
i++;
switch(ch)
{
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 ’0′:
printf(“ZERO “);
break;
}
}
}


By using/following this site you agree to our Legal Disclaimer

7 Comments »

  • Sony said:

    Hi Srikanth,

    How to print figures in Words? Like 1500 will be printed as “Fifteen hundred”, 10205 will be printed as “Ten thousand two hundred five”.

    Please mail me the code in “C” ASAP.

    Thanks,
    Sony

  • me said:

    How to use this code ? What extensino do we have to put ?

  • Srikanth (author) said:

    @ me

    Save the program in a notepad and change the extension from .txt to .c

  • Gopal said:

    i want program which print no given by user in words
    example:= 1999:=one thousand nine hundred ninty nine.

  • Jithu said:

    Hello, I’ve written a version that prints number in words like ‘one thousand nine hundred ninty nine’. Here’s it -

  • Jithu said:
  • HackMe!! said:

    How u can write so difficult..difficult programs?

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.