Hello friends today i'm sharing a program i.e very interesting,its code is little bit big but you can easily understand it.In This program you can enter any number(maximum 4 digit) after that this program convert that number to words.
for example:-"1234" is equivalent to "one thousand two hundred thirty four "
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char num[100],s[100];
int len,rem,n,j;
clrscr();
printf("\n Enter any number(maximam 4 digit):");
gets(num);
len=strlen(num);
n=atoi(num);
while(n!=0)
{
j=n;
while(j!=0)
{
rem=j%10;
j=j/10;
}
if(len!=2)
{
switch(rem)
{
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;
case 10:
printf(" ten ");
}
}
if(len==4)
printf(" thousand ");
else if(len==3)
printf(" hundred ");
else if(len==2)
{
if(n==11)
{
printf("eleven");
break;
}
else if(n==12)
{
printf("twelve");
break;
}
else if(n==13)
{
printf("thirteen");
break;
}
else if(n==14)
{
printf("fourteen");
break;
}
else if(n==15)
{
printf("fifteen");
break;
}
else if(n==16)
{
printf("sixteen");
break;
}
else if(n==17)
{
printf("seventeen");
break;
}
else if(n==18)
{
printf("eighteen");
break;
}
else if(n==19)
{
printf("ninteen");
break;
}
else if(n>=20&&n<30)
printf(" twenty ");
else if(n>=30&&n<40)
printf(" thirty ");
else if(n>=40&&n<50)
printf(" fourty ");
else if(n>=50&&n<60)
printf(" fifty ");
else if(n>=60&&n<70)
printf(" sixty ");
else if(n>=70&&n<80)
printf(" seventy ");
else if(n>=80&&n<90)
printf(" eighty ");
else if(n>=90&&n<100)
printf(" ninty ");
}
if(len==4)
n=n-(rem*1000);
else if(len==3)
n=n-(rem*100);
else if(len==2)
n=n-(rem*10);
else if(len==1)
n=n-rem;
itoa(n,s,10);
len=strlen(s);
n=atoi(s);
}
getch();
return(0);
}
for example:-"1234" is equivalent to "one thousand two hundred thirty four "
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char num[100],s[100];
int len,rem,n,j;
clrscr();
printf("\n Enter any number(maximam 4 digit):");
gets(num);
len=strlen(num);
n=atoi(num);
while(n!=0)
{
j=n;
while(j!=0)
{
rem=j%10;
j=j/10;
}
if(len!=2)
{
switch(rem)
{
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;
case 10:
printf(" ten ");
}
}
if(len==4)
printf(" thousand ");
else if(len==3)
printf(" hundred ");
else if(len==2)
{
if(n==11)
{
printf("eleven");
break;
}
else if(n==12)
{
printf("twelve");
break;
}
else if(n==13)
{
printf("thirteen");
break;
}
else if(n==14)
{
printf("fourteen");
break;
}
else if(n==15)
{
printf("fifteen");
break;
}
else if(n==16)
{
printf("sixteen");
break;
}
else if(n==17)
{
printf("seventeen");
break;
}
else if(n==18)
{
printf("eighteen");
break;
}
else if(n==19)
{
printf("ninteen");
break;
}
else if(n>=20&&n<30)
printf(" twenty ");
else if(n>=30&&n<40)
printf(" thirty ");
else if(n>=40&&n<50)
printf(" fourty ");
else if(n>=50&&n<60)
printf(" fifty ");
else if(n>=60&&n<70)
printf(" sixty ");
else if(n>=70&&n<80)
printf(" seventy ");
else if(n>=80&&n<90)
printf(" eighty ");
else if(n>=90&&n<100)
printf(" ninty ");
}
if(len==4)
n=n-(rem*1000);
else if(len==3)
n=n-(rem*100);
else if(len==2)
n=n-(rem*10);
else if(len==1)
n=n-rem;
itoa(n,s,10);
len=strlen(s);
n=atoi(s);
}
getch();
return(0);
}
Thanks Friends......
No comments:
Post a Comment
Please Give Me Your Views