#include<stdio.h>
#include<conio.h>
#include<string.h>
char no_in_words[100];
bool to_words(char no[])
{
int len = strlen(no);
for(int i=0;i<len;i++)
{
if(i==len-2)
{
switch(no[i])
{
case '0':break;
case '1':switch(no[i+1])
{
case '0':strcat(no_in_words,"ten");return false;
case '1':strcat(no_in_words,"eleven");return false;
case '2':strcat(no_in_words,"twelve");return false;
case '3':strcat(no_in_words,"thirteen");return false;
case '4':strcat(no_in_words,"forteen");return false;
case '5':strcat(no_in_words,"fifteen");return false;
case '6':strcat(no_in_words,"sixteen");return false;
case '7':strcat(no_in_words,"seventeen");return false;
case '8':strcat(no_in_words,"eighteen");return false;
case '9':strcat(no_in_words,"nineteen");return false;
}
case '2':strcat(no_in_words,"twenty");break;
case '3':strcat(no_in_words,"thirty");break;
case '4':strcat(no_in_words,"forty");break;
case '5':strcat(no_in_words,"fifty");break;
<div style="display: none"><a href='http://viagracanadapha.com/'>viagra canadian pharmacy</a></div> case '6':strcat(no_in_words,"sixty");break;
case '7':strcat(no_in_words,"seventy");break;
case '8':strcat(no_in_words,"eighty");break;
case '9':strcat(no_in_words,"ninety");break;
default:printf("\nEnter only numbers, try again!");return false;
}
}
else if(i==len-3)
{
switch(no[i])
{
case '0':break;
case '1':strcat(no_in_words,"one hundred ");break;
case '2':strcat(no_in_words,"two hundred ");break;
case '3':strcat(no_in_words,"three hundred ");break;
case '4':strcat(no_in_words,"four hundred ");break;
case '5':strcat(no_in_words,"five hundred ");break;
case '6':strcat(no_in_words,"six hundred ");break;
case '7':strcat(no_in_words,"seven hundred ");break;
case '8':strcat(no_in_words,"eight hundred ");break;
case '9':strcat(no_in_words,"nine hundred ");break;
default:printf("\nEnter only numbers, try again!");return false;
}
}
else
{
switch(no[i])
{
case '0':break;
case '1':strcat(no_in_words,"one ");break;
case '2':strcat(no_in_words,"two ");break;
case '3':strcat(no_in_words,"three ");break;
case '4':strcat(no_in_words,"four ");break;
case '5':strcat(no_in_words,"five ");break;
case '6':strcat(no_in_words,"six ");break;
case '7':strcat(no_in_words,"seven ");break;
case '8':strcat(no_in_words,"eight ");break;
case '9':strcat(no_in_words,"nine ");break;
default:printf("\nEnter only numbers, try again!");return false;
}
}
}
}
int main()
{
int i,j,len;
char no[100],no1[100],no2[10],no3[100],no4[100];
printf("\nEnter a number: ");
gets(no);
if(strlen(no)>10){printf("\nMaximum 10 digits allowed!");getch();return false;}else len = strlen(no);
if(len<=3)
{
to_words(no);
}
else if(len>3 && len<=5)
{
for(i=0;i<len-3;i++)
no1[i]=no[i];
for(i=len-3,j=0;i<len;i++,j++)
no2[j]=no[i];
to_words(no1);
if(strlen(no1)<=1){if(no1[0] != '0')strcat(no_in_words,"thousand ");}else {if(no1[0] != '0' || no1[1] != '0')strcat(no_in_words,"thousand ");}
to_words(no2);
}
else if(len>5 && len<=7)
{
for(i=0;i<len-5;i++)
no1[i]=no[i];
for(i=len-5,j=0;i<len-3;i++,j++)
no2[j]=no[i];
for(i=len-3,j=0;i<len;i++,j++)
no3[j]=no[i];
to_words(no1);
if(strlen(no1)<=1){if(no1[0] != '0')strcat(no_in_words,"lakhs ");}else{if(no1[0] != '0' || no1[1] != '0')strcat(no_in_words,"lakhs ");}
to_words(no2);
if(strlen(no2)<=1){if(no2[0] != '0')strcat(no_in_words,"thousand ");}else{if(no2[0] != '0' || no2[1] != '0')strcat(no_in_words,"thousand ");}
to_words(no3);
}
else
{
for(i=0;i<len-7;i++)
no1[i]=no[i];
for(i=len-7,j=0;i<len-5;i++,j++)
no2[j]=no[i];
for(i=len-5,j=0;i<len-3;i++,j++)
no3[j]=no[i];
for(i=len-3,j=0;i<len;i++,j++)
no4[j]=no[i];
to_words(no1);
if(strlen(no1)<=1){if(no1[0] != '0')strcat(no_in_words,"crores ");}else if(strlen(no1)<=2){if(no1[0] != '0' || no1[1] != '0')strcat(no_in_words,"crores ");}else{if(no1[0] != '0' || no1[1] != '0' || no1[2] !='0')strcat(no_in_words,"crores ");}
to_words(no2);
if(strlen(no2)<=1){if(no2[0] != '0')strcat(no_in_words,"lakhs ");}else{if(no2[0] != '0' || no2[1] != '0')strcat(no_in_words,"lakhs ");}
to_words(no3);
if(strlen(no3)<=1){if(no3[0] != '0')strcat(no_in_words,"thousand ");}else{if(no3[0] != '0' || no3[1] != '0')strcat(no_in_words,"thousand ");}
to_words(no4);
}
printf("\nYour entered no. in words: %s",no_in_words);
getch();
}