Sunday, May 7, 2017

Number to word conversion


C program for number to word conversion.

#include<stdio.h>
#include<conio.h>
int main()
{
  char  number[20] ;  
  int i;

  printf("Enter number: ");
  gets(number);

  printf("%s in words:", number);
  
  for(i=0 ; number[i] != '\0' ; i++)
  {
    switch(number[i])  
    {
      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;
 default:  printf("Error ");
  break;
    }
  }
  return 0;
}

Run-1 Output of program:

Enter number: 4321
4321 in words:Four Three Two One

Run-2 Output of program:

Enter number: 12AB34
12AB34 in words:One Two Error Error Three Four

No comments:

Post a Comment