Home  Interview Questions  Certifications  Aptitude Questions  Tutorials  Placement Papers  Search  Resume  Soft Skills  Video  Forum  Blog

Programming Source Codes
C/C++ Source Codes
C# Source Codes
.........More

Aptitude Interview Questions
C/C++ Aptitude Questions
C Aptitude Questions
.........More

Tutorials
C Tutorial
C++ Tutorial
.........More

# C/C++ Source Codes

print the equivalent English of a number

# include <ctype.h>
# include <stdio.h>
#include<conio.h>

char *ot[3][9] = {
{ " One", " Two", " Three", " Four", " Five",
" Six", " Seven", " Eight", " Nine" },
{ " Ten", " Twenty", " Thirty", " Forty", " Fifty",
" Sixty", " Seventy", " Eighty", " Ninety" },
{ " Eleven", " Twelve", " Thirteen", " Fourteen",
" Fifteen"," Sixteen"," Seventeen"," Eighteen", " Nineteen"}
};

char *a[5] = { " Hundred", " Thousand", " Lakhs", " Crore", " Arab" } ;
char result[250] = "" ;
char *t[50] ;

main( )
{
int i, j, ind = 0, c, r, pr = -1, e = 0 ;
unsigned long n ;
unsigned long q ;

clrscr( ) ;
printf ( "\nEnter a number : " ) ;
scanf ( "%ld", &n ) ;
printf ( "%ld\n", n ) ;
q = n ;
if ( n == 0 )
strcpy ( result, "Zero" ) ;
else
{
for( i = 0 ; q > 0 ; i++ )
{
if( ( i % 2 ) && i > 2 )
e++ ;
r = q % 10 ;
q /= 10 ;
if ( r != 0 )
{
if ( i == 0 )
t[++ind] = ot[i][r-1];
else if ( i == 1 )
{
if ( r == 1 && pr == 0 )
t[++ind] = ot[i][r-1] ;
else if ( r == 1 && pr > 0 )
t[--ind] = ot[2][r-1] ;
else
t[++ind] = ot[i][r-1] ;
}
else if ( i >= 2 )
{
if ( i == 2 )
{
t[++ind] = a[e] ;
t[++ind] = ot[0][r-1] ;
}
else
{
if ( i % 2 )
{
t[++ind] = a[e] ;
t[++ind] = ot[0][r-1] ;
}
else
{
if ( pr == 0 )
{
t[++ind] = a[e] ;
t[++ind] = ot[1][r-1] ;
}
else if ( r == 1)
t[ind] = ot[2][pr-1] ;
else
t[++ind] = ot[1][r-1] ;
}
}
}
}
pr = r ;
}
}/* End for */

for ( i = ind ; i >= 0 ; i-- )
strcat ( result, t[i] ) ;

printf( "\n%s", result ) ;

getch();
} /* End main */

Have a Question ? post your questions here. It will be answered as soon as possible.

Check Object Oriented Interview Questions for more Object Oriented Interview Questions with answers

Check Data Structure Interview Questions for more data structure interview questions with answers