Write C/C++/Java code to convert given number into words.
eg:- Input: 1234
Output: One thousand two hundred thirty-four.
Input: 10
Output: Ten
#include
#include
void main()
{
int len=0,revnum,i,dup=0,j=0,k=0;
long int gvalue;
char ones[] [10]={"one","Two","Three","Four","Five","Six","Seven","Eight","Nine","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen",""};
char twos[][10]={"Ten","Twenty","Thirty","Fourty","fifty","Sixty","Seventy","eighty","Ninety",""};
clrscr();
printf("\n Enter value");
scanf("%ld",&gvalue);
if(gvalue==10)
printf("Ten");
else if(gvalue==100)
printf("Hundred");
else if(gvalue==1000)
printf("Thousand");
dup=gvalue;
for(i=0;dup>0;i++)
{
revnum=revnum*10+dup%10;
len++;
dup=dup/10;
}
while(j10&&gvalue<=19)
{
printf("%s ",ones[gvalue-2]);
break;
}
else if(gvalue>19&&gvalue<100)
{
k=gvalue/10;
gvalue=gvalue%10;
printf("%s ",twos[k-1]);
}
else if(gvalue>100&&gvalue<1000)
{
k=gvalue/100;
gvalue=gvalue%100;
printf("%s Hundred ",ones[k-1]);
}
else if(gvalue>=1000&&gvlaue<9999)
{
k=gvalue/1000;
gvalue=gvalue%1000;
printf("%s Thousand ",ones[k-1]);
}
else if(gvalue>=11000&&gvalue<=19000)
{
k=gvalue/1000;
gvalue=gvalue%1000;
printf("%s Thousand ",twos[k-2]);
}
else if(gvalue>=12000&&gvalue<100000)
{
k=gvalue/10000;
gvalue=gvalue%10000;
printf("%s ",ones[gvalue-1]);
}
else
{
printf("");
}
j++;
getch();
}