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

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the maximum no. of arguments that can be given in a command line in C.?

674


What is a pointer variable in c language?

649


Explain the use of 'auto' keyword in c programming?

685


What is #define used for in c?

618


What is #define?

578






Explain enumerated types in c language?

608


What is the use of function in c?

715


How many bytes is a struct in c?

730


Explain how do you sort filenames in a directory?

613


What is variable declaration and definition in c?

505


write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.

2273


What are different storage class specifiers in c?

623


What does %d do in c?

548


What are pragmas and what are they good for?

580


What is data type long in c?

627