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
How can I implement sets or arrays of bits?
How many parameters should a function have?
Explain how do you print an address?
For what purpose null pointer used?
Do you have any idea how to compare array with pointer in c?
if a is an integer variable, a=5/2; will return a value a) 2.5 b) 3 c) 2 d) 0
what do the 'c' and 'v' in argc and argv stand for?
What are the difference between a free-standing and a hosted environment?
Is null a keyword in c?
What do you mean by scope of a variable in c?
hi any body pls give me company name interview conduct "c" language only
What is line in c preprocessor?
Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?
How can I find out if there are characters available for reading?
void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }