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

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / mayank

/*write a program to accept any number up to five digits and
print that in words(without using array). for example- 1265=
one two six five*/
#include<stdio.h>
#include<stdlib.h>
main()
{
int x,mod, rev=0;
printf("enter number(up to five digits)");
scanf("%d", &x);
if(x>99999)
{
printf("invalid number");
exit(0);
}
while(x>0)
{
mod=x%10;
rev=rev*10+mod;
x=x/10;
}
while(rev>0)
{
mod=rev%10;
switch(mod)
{
case 1:
printf("one ");
break;
case 2:
printf("two ");
break;
case 3:
printf("three ");
break;
case 4:
printf("four ");
break;
case 5:
printf("five ");
break;
case 6:
printf("six " );
break;
case 7:
printf("seven ");
break;
case 8:
printf("eight ");
break;
case 9:
printf("nine ");
break;
case 0:
printf("zero ");
break;
}
rev=rev/10;
}
printf("\n");
}

Is This Answer Correct ?    30 Yes 12 No

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

Answer / rakesh.bit

# include <stdio.h>
int main ()
{
int n,temp,t,s=0,i,ctr=0;
char a[10][10] = {"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine"};
printf ("Enter the number:\n");
scanf ("%d", &n);
//printf ("The given num in word = %s\n", a[n]);
t=n;
while(n>0)
{
ctr++;
n=n/10;
}
while(t>0)
{
temp=t%10;
s=10*s+temp;
t=t/10;
}

for(i=0;i<ctr;i++)
{
printf("%s",a[s%10]);
s=s/10;
}
}

Is This Answer Correct ?    22 Yes 16 No

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

Answer / sachin patel

#include<stdio.h>
#include<conio.h>
void main()
{
int no;
printf("Enter the no");
scanf("%d",&no);
switch(no)
{
case 1:
printf("One");
break;
case 2:
printf("Two");
break;
case 3:
printf("Three");
break;
case 4:
printf("Four");
break;
case 5:
printf("Five");
break;
case 6:
printf("Six");
break;
case 7:
printf("Seven");
break;
case 8:
printf("Eight");
break;
case 9:
printf("Nine");
break;
default:
printf("You entered Wrong input");
break;
}
}

Is This Answer Correct ?    8 Yes 5 No

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

Answer / siddiqui_1985

i dont have answer i'm actually asking question..

What if we want to print upto nth term??

in a very first post
"


#include<stdioi.h>
void main()
{
int n,count=0,a[20];
scanf("%d",&n);
for(i=0;n>0;i++)
{
a[i]=n%10;
n=n/10;
count++;
}
for(i=0;i<count;i++)
{
switch(a[i])
{
case 1:
printf("one");
break;
case 2:
printf("two");
break;
"

he explicitly doing this using switch case.

Is This Answer Correct ?    6 Yes 5 No

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

Answer / vaibhav dubey

in ans #8,if we,even,reverse the number we can'nt get right
ans in all cases.for example if we enter 1000 than it will
be reversed 0001 and computer will [rint 1 only

Is This Answer Correct ?    3 Yes 3 No

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

Answer / manoj kumar

the program u wrote is wrong because it prints in reverse
means if u gave 12345 the output will be five four three
two one like this
for getting correct output the given number would be
reversed and we write code for that reversed number.

Is This Answer Correct ?    27 Yes 30 No

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

Answer / swathi

# include <stdio.h>
int main ()
{
int n;
char a[10][10] = {"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine"};
printf ("Enter the number:\n");
scanf ("%d", &n);
printf ("The given num in word = %s\n", a[n]);
}

Is This Answer Correct ?    26 Yes 36 No

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

Answer / vignesh1988i

OK HERE they are asking for 5 digits , but if somewhere
they ask for 'n' digit numbers , then that a[6] wont work
there , Whenever u do a program u will also think of the
worst cases then only we must develop a program...... in all
situations ur program should work!!!!!!!! that's speaks !!

thank u

Is This Answer Correct ?    25 Yes 37 No

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

Answer / prawin62

they directly asks for 5 digit naaa

so read that into a c[6] like that

and print c[0] thousand like that..........

Is This Answer Correct ?    32 Yes 83 No

Post New Answer

More C Interview Questions

How can type-insensitive macros be created?

0 Answers  


Q.1 write a program to create binary tree 1 to 16 numbers? Q.2 write a program to creat a binary search tree for the member that is given by user?

0 Answers   Case, IBM,


please explain every phase in the "SDLC" in the dotnet.

0 Answers  


Why main is used in c?

0 Answers  


C program to find frequency of each character in a text file?

6 Answers  






#include<stdio.h> int f(int,int); int main() { printf("%d",f(20,1)); return 0; } int f(int n,int k) { if(n==0) return 0; else if(n%2)return f(n/2,2*k)+k; else return f(n/2,2*k)-k; } how this program is working and generating output as 9....?

1 Answers  


what's the o/p int main(int n, char *argv[]) { char *s= *++argv; puts(s); exit(0); }

1 Answers   Motorola,


What is the difference between fread buffer() and fwrite buffer()?

0 Answers  


What are .h files and what should I put in them?

3 Answers  


Reverse the bit order in a single macro. eg. i/p = 10010101 --> o/p = 10101001

2 Answers  


a construct the"else" part of "if" statement contains anoth "if else" statement is called a) if-else b) else-if-else c) if-else-if-else d) chain if/if-else-if

0 Answers  


What is the difference between declaring a variable by constant keyword and #define ing that variable?

1 Answers  


Categories