C Program to Read a Number and Displaying Its Digit in Words in Reverse Order


In this C program, we are going to read a number and displaying its digit in words in reverse order.

For example: If given number is 6739 then output of this program will be Nine Three Seven Six

Program


#include
#include

int main()
{
	 long int number, rem;
	 clrscr();
	 printf("Enter number: ");
	 scanf("%ld", &number);
	
	 /* Printing Each digits in words */
	 while(number != 0)
	 {
		  rem = number%10;
		
		  switch(rem)
		  {
			   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;
		  }
		
		  number = number/10;
	 }
	 getch();
	 return(0);
}

Output of the above program :

Run 1:
------------
Enter number: 67395 ↲ 
Five Nine Three Seven Six

Run 2:
------------
Enter number: 13125 ↲  
Five Two One Three One

Note: ↲ indicates ENTER is pressed.