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
What is meant by preprocessor in c?
Sir,please help me out with the code of this question. Write an interactive C program that will encode or decode multiple lines of text. Store the encoded text within a data file, so that it can be retrieved and decoded at any time. The program should include the following features: (a) Enter text from the keyboard, encode the text and store the encoded text in a data file. (b) Retrieve the encoded text and display it in its encoded form. (c) Retrieve the encoded text, decode it and then display the decoded text. (d) End the computation. Test the program using several lines of text of your choice.
How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?
Explain zero based addressing.
What is the right type to use for boolean values in c?
Explain what is the benefit of using #define to declare a constant?
Describe wild pointers in c?
What would happen to X in this expression: X += 15; (assuming the value of X is 5)
Explain how can I pad a string to a known length?
Explain the use of 'auto' keyword
What is the newline escape sequence?
What are extern variables in c?
what is use of malloc and calloc?
what is the difference between 123 and 0123 in c?
What are the keywords in c?