C program to Print Number in Words

C Program :
/* Aim: Write a program,which accepts a number n and displays each digit in words.
Example:6278 Output: Six Two Seven Eight */ 

#include<stdio.h&>
void main()
{ 
	int d,num,rev=0,r;
 
	printf("\n Enter any number:");
	scanf("%d",&num);
	printf("\n ");
  
	do
	{ 
	d=num%10;
	num=num/10;
	rev=rev*10+d;
	}while(num>0);
 
	do
	{ 
	r=rev%10;
	rev=rev/10;
 
	switch(r)
	{
	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;
	}}while(rev>0);
}
 

/* Output of above code:-

 Enter any number:1234

 One Two Three Four 

*/ 

Comments