Input an amount and print it in words.
#include <stdio.h>
#include <conio.h>
void main ( )
{
char tenth[10][40] = {"Ten","Eleven","Twelve","Thirteen","Forteen","Fifteen",
"Sixteen","Seventeen","Eighteen","Nineteen"};
char dig[10][20] = {"","One","Two","Three","Four","Five","Six","Seven",
"Eight","Nine"};
char tense[10][40] = {"","","Twenty","Thirty","Forty","Fifty","Sixty","Seventy",
"Eighty","Ninety"};
int d1,d2,d3,n,r,d5,d4;
clrscr ( );
printf("\n\n\n\t Enter a amount in Rs. (less than 32767)..:"); scanf("%d",&n);
d5 = n % 10;
n = n / 10;
d4 = n % 10;
n = n / 10;
d3 = n % 10;
n = n / 10;
d2 = n % 10;
n = n / 10;
d1 = n%10;
printf("\n\n\n\t Rupees in words...:");
if ( d1 == 0 && d2 != 0 )
{
printf("%s thousand ",dig[d2] );
}
else if ( d1 == 1)
{
printf("%s thousand ",tenth[d1] );
}
else if ( d1 != 1 && d1 != 0 )
{
printf("%s %s thousand ",tense[d1],dig[d2] );
}
if( d3 != 0 )
{
printf("%s hundred ",dig[d3] );
}
if( d4 == 1 )
{
printf("%s",tenth[d5] );
}
else
{
printf("%s %s",tense[d4],dig[d5] );
}
getch ( );
}
Click here to contact us
#include <stdio.h>
#include <conio.h>
void main ( )
{
char tenth[10][40] = {"Ten","Eleven","Twelve","Thirteen","Forteen","Fifteen",
"Sixteen","Seventeen","Eighteen","Nineteen"};
char dig[10][20] = {"","One","Two","Three","Four","Five","Six","Seven",
"Eight","Nine"};
char tense[10][40] = {"","","Twenty","Thirty","Forty","Fifty","Sixty","Seventy",
"Eighty","Ninety"};
int d1,d2,d3,n,r,d5,d4;
clrscr ( );
printf("\n\n\n\t Enter a amount in Rs. (less than 32767)..:"); scanf("%d",&n);
d5 = n % 10;
n = n / 10;
d4 = n % 10;
n = n / 10;
d3 = n % 10;
n = n / 10;
d2 = n % 10;
n = n / 10;
d1 = n%10;
printf("\n\n\n\t Rupees in words...:");
if ( d1 == 0 && d2 != 0 )
{
printf("%s thousand ",dig[d2] );
}
else if ( d1 == 1)
{
printf("%s thousand ",tenth[d1] );
}
else if ( d1 != 1 && d1 != 0 )
{
printf("%s %s thousand ",tense[d1],dig[d2] );
}
if( d3 != 0 )
{
printf("%s hundred ",dig[d3] );
}
if( d4 == 1 )
{
printf("%s",tenth[d5] );
}
else
{
printf("%s %s",tense[d4],dig[d5] );
}
getch ( );
}
Click here to contact us
No comments:
Post a Comment