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 sizeof int in c?
What is the sizeof () a pointer?
Is there anything like an ifdef for typedefs?
What is zero based addressing?
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..
Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions?
The performance of an operation in several steps with each step using the output of the preceding step a) recursion b) search c) call by value d) call by reference
How was c created?
Why functions are used in c?
What are the advantages of external class?
What is the value of a[3] if integer a[] = {5,4,3,2,1}?
A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers
Explain how are 16- and 32-bit numbers stored?
Write a program to swap two numbers without using third variable?
What is typedf?