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
Explain what happens if you free a pointer twice?
How do you list a file’s date and time?
Why do some versions of toupper act strangely if given an upper-case letter?
Can a local variable be volatile in c?
What does int main () mean?
Write an algorithm for implementing insertion and deletion operations in a singly linked list using arrays ?
I need a sort of an approximate strcmp routine?
What is a void pointer? When is a void pointer used?
Give the rules for variable declaration?
Which type of language is c?
What was noalias and what ever happened to it?
What is the benefit of using #define to declare a constant?
Explain the use of 'auto' keyword in c programming?
How do I swap bytes?
What is the scope of an external variable in c?