===========================================================================
CODING
#include<all.h>
void main()
{
clrscr();
char *place,*a1,*a2,*a3;
char str[80];
int n,i,a,m;
first();
second();
cprintf("Enter any no. to convert into Words: ");
gets(str);
for(i=0;str[i]!='\0';i++);
for(n=i,m=0,i=0;str[i]!='\0';i++,n--)
{
switch(n)
{
case 8:
if(str[i]-48==0)
strcpy(place,"");
else
strcpy(place,"Crore ");
break;
case 6:
if(str[i]-48==0 && str[i-1]-48==0)
strcpy(place,"");
else
strcpy(place,"Lakh ");
break;
case 4:
if(str[i]-48==0 && str[i-1]-48==0)
strcpy(place,"");
else
strcpy(place,"Thousand ");
break;
case 3:
if(str[i]-48==0)
strcpy(place,"");
else
strcpy(place,"Hundred ");
break;
default:strcpy(place,"");
}
switch(a=str[i]-48)
{
case 1:
strcpy(a1,"One ");
strcpy(a2,"Eleven ");
strcpy(a3,"Ten ");
break;
case 2:
strcpy(a1,"Two ");
strcpy(a2,"Tweleve ");
strcpy(a3,"Twenty ");
break;
case 3:
strcpy(a1,"Three ");
strcpy(a2,"Thirteen ");
strcpy(a3,"Thirty ");
break;
case 4:
strcpy(a1,"Four ");
strcpy(a2,"Fourteen ");
strcpy(a3,"Forty ");
break;
case 5:
strcpy(a1,"Five ");
strcpy(a2,"Fifteen ");
strcpy(a3,"Fifty ");
break;
case 6:
strcpy(a1,"Six ");
strcpy(a2,"Sixteen ");
strcpy(a3,"Sixty ");
break;
case 7:
strcpy(a1,"Seven ");
strcpy(a2,"Seventeen ");
strcpy(a3,"Seventy ");
break;
case 8:
strcpy(a1,"Eight ");
strcpy(a2,"Eighteen ");
strcpy(a3,"Eighty ");
break;
case 9:
strcpy(a1,"Nine ");
strcpy(a2,"Nineteen ");
strcpy(a3,"Ninety ");
break;
default:
strcpy(a1,"");
strcpy(a2,"");
strcpy(a3,"");
}
if(n==5)
{
if(str[i]-48==1)
m=1;
else
cprintf("%s",a3);
}
else if(n==7)
{
if(str[i]-48==1)
m=1;
else
cprintf("%s",a3);
}
else if(n==2)
{
if(str[i]-48==1)
m=1;
else
cprintf("%s",a3);
}
else if(n==1)
{
if(m==1)
{
cprintf("%s",a2);
m=0;
}
else
cprintf("%s",a1);
}
else
{
if(m==1)
{
cprintf("%s%s",a2,place);
m=0;
}
else
cprintf("%s%s",a1,place);
}
}
getch();
}
CODING
#include<all.h>
void main()
{
clrscr();
char *place,*a1,*a2,*a3;
char str[80];
int n,i,a,m;
first();
second();
cprintf("Enter any no. to convert into Words: ");
gets(str);
for(i=0;str[i]!='\0';i++);
for(n=i,m=0,i=0;str[i]!='\0';i++,n--)
{
switch(n)
{
case 8:
if(str[i]-48==0)
strcpy(place,"");
else
strcpy(place,"Crore ");
break;
case 6:
if(str[i]-48==0 && str[i-1]-48==0)
strcpy(place,"");
else
strcpy(place,"Lakh ");
break;
case 4:
if(str[i]-48==0 && str[i-1]-48==0)
strcpy(place,"");
else
strcpy(place,"Thousand ");
break;
case 3:
if(str[i]-48==0)
strcpy(place,"");
else
strcpy(place,"Hundred ");
break;
default:strcpy(place,"");
}
switch(a=str[i]-48)
{
case 1:
strcpy(a1,"One ");
strcpy(a2,"Eleven ");
strcpy(a3,"Ten ");
break;
case 2:
strcpy(a1,"Two ");
strcpy(a2,"Tweleve ");
strcpy(a3,"Twenty ");
break;
case 3:
strcpy(a1,"Three ");
strcpy(a2,"Thirteen ");
strcpy(a3,"Thirty ");
break;
case 4:
strcpy(a1,"Four ");
strcpy(a2,"Fourteen ");
strcpy(a3,"Forty ");
break;
case 5:
strcpy(a1,"Five ");
strcpy(a2,"Fifteen ");
strcpy(a3,"Fifty ");
break;
case 6:
strcpy(a1,"Six ");
strcpy(a2,"Sixteen ");
strcpy(a3,"Sixty ");
break;
case 7:
strcpy(a1,"Seven ");
strcpy(a2,"Seventeen ");
strcpy(a3,"Seventy ");
break;
case 8:
strcpy(a1,"Eight ");
strcpy(a2,"Eighteen ");
strcpy(a3,"Eighty ");
break;
case 9:
strcpy(a1,"Nine ");
strcpy(a2,"Nineteen ");
strcpy(a3,"Ninety ");
break;
default:
strcpy(a1,"");
strcpy(a2,"");
strcpy(a3,"");
}
if(n==5)
{
if(str[i]-48==1)
m=1;
else
cprintf("%s",a3);
}
else if(n==7)
{
if(str[i]-48==1)
m=1;
else
cprintf("%s",a3);
}
else if(n==2)
{
if(str[i]-48==1)
m=1;
else
cprintf("%s",a3);
}
else if(n==1)
{
if(m==1)
{
cprintf("%s",a2);
m=0;
}
else
cprintf("%s",a1);
}
else
{
if(m==1)
{
cprintf("%s%s",a2,place);
m=0;
}
else
cprintf("%s%s",a1,place);
}
}
getch();
}
===========================================================================
No comments:
Post a Comment