Sunday 28 February 2016

Convert any number to word

Q. Write a C program to convert any number to words, for example if 
user entered number = 45764then 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;

}

No comments:

Post a Comment

Ads Inside Post