6.30.2014

Convert any number to word

Q. Write a C program to convert any number to words, for example if 
user entered number = 45764
then output = Four Five Seven Six Four

Ans.

/*c program for convert number to word*/
#include<stdio.h>
int main()
{

 int num,c,digit,r=0;
 char *ch[1000];
 printf("Enter Number/Digit : ");
 scanf("%d", &num);
 while(num)
 {
  digit=num%10;
  num=num/10;
  switch(digit)
  {
    case 0: ch[r++]="Zero"; break;
    case 1: ch[r++]="One"break;
    case 2: ch[r++]="Two"break;
    case 3: ch[r++]="Three"break;
    case 4: ch[r++]="Four"break;
    case 5: ch[r++]="Five"break;
    case 6: ch[r++]="Six"break;
    case 7: ch[r++]="Seven"break;
    case 8: ch[r++]="Eight"break;
    case 9: ch[r++]="Nine"break;
  }
 }
 printf("Your Entered Number In Word : ");
 for(c=r; c>=0; c--)
    printf("%s", ch[c]);
 getch();
 return 0;
}


/************************************************************

The output of above program would be:
**************************************************************/

Output for Convert number to word C program
Figure: Screen shot for Convert number to word C program


Related program:

  1. Convert any number to grammatical words C program
  2. Comparison of million/billion/trillion VS lakh/crore/kharab

1 comment: