#include<stdio.h>
#include<conio.h>
struct std{
int dig;
char wrd[20];
};
struct std fig[]={{1,"one"},{2,"two"},{3,"three"},{4,"four"},{5,"five"},{6,"six"},{7,"seven"},{8,"eight"},{9,"nine"},{10,"ten"},{11,"eleven"},{12,"twelve"},{13,"thirteen"},{14,"fourteen"},{15,"fifteen"},{16,"sixteen"},{17,"seventeen"},{18,"eighteen"},{19,"nineteen"},{20,"twenty"},{30,"thirty"},{40,"fourty"},{50,"fifty"},{60,"sixty"},{70,"seventy"},{80,"eighty"},{90,"ninety"}};
int num1[5],i;
op0(long num)
{
for(i=0;i<20;i++)
if(fig[i].dig==num)
printf("%s",fig[i].wrd);
}
op1(long num)
{ //num1=num;
num1[0]=num/10;
num1[0]=num1[0]*10;
num1[1]=num%10;
for(i=0;i<27;i++)
{if(fig[i].dig==num1[0])
printf("%s ",fig[i].wrd);
}
for(i=0;i<20;i++)
{if(fig[i].dig==num1[1])
printf("%s",fig[i].wrd);
}
}
op2(long num)
{
int k,j=num%100;
k=num/100;
for(i=0;i<10;i++)
{if(fig[i].dig==k)
{printf("%s hundred ",fig[i].wrd);
if(j>0&&j<20)
op0(num%100);
else
op1(num%100);
}
}
}
op3(long num)
{
int k,j=num%1000;
k=num/1000;
for(i=0;i<10;i++)
{ if(fig[i].dig==k)
{ printf("%s thousand ",fig[i].wrd);
if(j>=1&&j<10)
op0(num%1000);
else if(j>10&&j<100)
op1(num%1000);
else
op2(num%1000);
}
}
}
op4(long num)
{
int k=num/1000,j;
j=num%1000;
if(k<=20)
{
op0(num/1000);
printf(" thousand ");
if(j>0&&j<10)
op0(num%1000);
if(j>10&&j<100)
op1(num%1000);
else op2(num%1000);
}
if((k>20)&&(k<100))
{
op1(num/1000);
printf(" thousand ");
if(j>0&&j<10)
op0(num%1000);
if(j>10&&j<100)
op1(num%1000);
else op2(num%1000);
}
//op2(num%1000);
}
op5(long num)
{
int k=num/100000;
int j=num%100000;
for(i=0;i<10;i++)
{ if(fig[i].dig==k)
{ printf("%s lakh ",fig[i].wrd);
if(j>0&&j<20)
op0(num%100000);
if(j>20&&j<100)
op1(num%100000);
if(j>100&&j<1000)
op2(num%100000);
if(j>1000&&j<10000)
op3(num%100000);
if(j>10000&&j<100000)
op4(num%100000);
}
}
}
main()
{
long num;
clrscr();
printf("\n\nEnter the number lessthan one lack\n\n");
scanf("%ld",&num);
if(num<=20)
op0(num);
if((num>20)&&(num/100==0))
op1(num);
if(num==100)
printf("hundred");
if(num>100&&num<1000)
op2(num);
if(num==1000) printf("\none thousand");
if(num>1000&&num<10000)
op3(num);
if(num==10000) printf("\nten thousand");
if(num>10000&&num<100000)
op4(num);
if(num==100000) printf("\none lakh");
if(num>100000&&num<1000000)
op5(num);
if(num==1000000)
printf("\nOne crore");
getch();
}
#include<conio.h>
struct std{
int dig;
char wrd[20];
};
struct std fig[]={{1,"one"},{2,"two"},{3,"three"},{4,"four"},{5,"five"},{6,"six"},{7,"seven"},{8,"eight"},{9,"nine"},{10,"ten"},{11,"eleven"},{12,"twelve"},{13,"thirteen"},{14,"fourteen"},{15,"fifteen"},{16,"sixteen"},{17,"seventeen"},{18,"eighteen"},{19,"nineteen"},{20,"twenty"},{30,"thirty"},{40,"fourty"},{50,"fifty"},{60,"sixty"},{70,"seventy"},{80,"eighty"},{90,"ninety"}};
int num1[5],i;
op0(long num)
{
for(i=0;i<20;i++)
if(fig[i].dig==num)
printf("%s",fig[i].wrd);
}
op1(long num)
{ //num1=num;
num1[0]=num/10;
num1[0]=num1[0]*10;
num1[1]=num%10;
for(i=0;i<27;i++)
{if(fig[i].dig==num1[0])
printf("%s ",fig[i].wrd);
}
for(i=0;i<20;i++)
{if(fig[i].dig==num1[1])
printf("%s",fig[i].wrd);
}
}
op2(long num)
{
int k,j=num%100;
k=num/100;
for(i=0;i<10;i++)
{if(fig[i].dig==k)
{printf("%s hundred ",fig[i].wrd);
if(j>0&&j<20)
op0(num%100);
else
op1(num%100);
}
}
}
op3(long num)
{
int k,j=num%1000;
k=num/1000;
for(i=0;i<10;i++)
{ if(fig[i].dig==k)
{ printf("%s thousand ",fig[i].wrd);
if(j>=1&&j<10)
op0(num%1000);
else if(j>10&&j<100)
op1(num%1000);
else
op2(num%1000);
}
}
}
op4(long num)
{
int k=num/1000,j;
j=num%1000;
if(k<=20)
{
op0(num/1000);
printf(" thousand ");
if(j>0&&j<10)
op0(num%1000);
if(j>10&&j<100)
op1(num%1000);
else op2(num%1000);
}
if((k>20)&&(k<100))
{
op1(num/1000);
printf(" thousand ");
if(j>0&&j<10)
op0(num%1000);
if(j>10&&j<100)
op1(num%1000);
else op2(num%1000);
}
//op2(num%1000);
}
op5(long num)
{
int k=num/100000;
int j=num%100000;
for(i=0;i<10;i++)
{ if(fig[i].dig==k)
{ printf("%s lakh ",fig[i].wrd);
if(j>0&&j<20)
op0(num%100000);
if(j>20&&j<100)
op1(num%100000);
if(j>100&&j<1000)
op2(num%100000);
if(j>1000&&j<10000)
op3(num%100000);
if(j>10000&&j<100000)
op4(num%100000);
}
}
}
main()
{
long num;
clrscr();
printf("\n\nEnter the number lessthan one lack\n\n");
scanf("%ld",&num);
if(num<=20)
op0(num);
if((num>20)&&(num/100==0))
op1(num);
if(num==100)
printf("hundred");
if(num>100&&num<1000)
op2(num);
if(num==1000) printf("\none thousand");
if(num>1000&&num<10000)
op3(num);
if(num==10000) printf("\nten thousand");
if(num>10000&&num<100000)
op4(num);
if(num==100000) printf("\none lakh");
if(num>100000&&num<1000000)
op5(num);
if(num==1000000)
printf("\nOne crore");
getch();
}
Sample Output :
Enter the number lessthan one lack
99999
ninety nine thousand nine hundred ninety nine
Enter the number lessthan one lack
99999
ninety nine thousand nine hundred ninety nine