Write a program in c to input a 5 digit number and print it
in words.

Answer Posted / sunil

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

char a[10][12]={"one","two","three","four","five","six","seven","eight","nine"};
char b[10][15]={"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","ninteen"};
char tens[10][15]={"twenty","thirty","fourtey","fiftey","sixty","seventy","eighty","ninty"};

int check(long int num)
{
if(num>10000000)return 5;
if(num>100000)return 4;
else if(num>1000)return 1;
else if(num>100)return 2;
else if(num>10)return 3;
else

return 0;
}

void prnt(long int num,char *s)
{ int n;
if(num<10)
{
printf(" %s %s",a[num-1],s);

}
else if(num>10 && num<20)
{
printf(" %s %s",b[(num-10)-1],s);
}
else if(num>20)
{
printf(" %s ",tens[(num-20)/10]);

n=num%10;
printf(" %s %s",a[n-1],s);
}

}

void main()
{
long int num,n;
int ch=1;

printf("enter no\n");
scanf("%ld",&num);

while( ch!=0)
{

ch=check(num);

// if(ch==0)
// goto l1;

switch(ch)
{
case 1:
n=num/1000;
prnt(n," thousand");
num=num-n*1000;
break;
case 2:
n=num/100;
prnt(n," hundred ");
num=num-n*100;
break;
case 3:
printf(" %s",tens[(num-20)/10]);
num=num%10;
break;
case 4:
n=num/100000;
prnt(n,"lacks");
num=num-n*100000;
break;
case 5:
n=num/10000000;
prnt(n,"crores");
num=num-n*10000000;
break;

}

}
printf(" %s",a[num-1]);
getch();
}

Is This Answer Correct ?    104 Yes 24 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a function simple definition?

604


Explain what is the heap?

612


If i have an array 0 to 99 i.e,(Size 100) I place the values 1 to 100 randomly like a[0]=29,a[1]=56 upto array[99].. the values are only between 1 to 100. getting the array values by using scanf.. If i entered one wrong element value line a[56]=108. how can i find it.. and also how to find the missing value in 1 to 100.. and i want to replace the missing values.. any one of them know please post your answer..

1581


What are the back slash character constants or escape sequence charactersavailable in c?

676


illustrate the use of address operator and dereferencing operator with the help of a program guys plzzz help for this question

1573






How pointer is different from array?

569


Difference between strcpy() and memcpy() function?

669


C program to find all possible outcomes of a dice?

1844


Is null valid for pointers to functions?

600


How many keywords are there in c?

581


Write the syntax and purpose of a switch statement in C.

612


Hai what is the different types of versions and their differences

1481


How would you rename a function in C?

610


Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]

619


What is const keyword in c?

734