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 function prototype?

769


Why pointers are used?

812


Explain what is the difference between functions getch() and getche()?

768


What is the difference between %d and %i?

781


Why does this code crash?

818






define string ?

845


How are portions of a program disabled in demo versions?

984


Explain how can I prevent another program from modifying part of a file that I am modifying?

840


What are global variables and explain how do you declare them?

769


Where are the auto variables stored?

827


hai iam working in sap sd module for one year and working in lumax ind ltd in desp department but my problem is i have done m.b.a in hr/marketing and working sap sd there is any combination it. can you give right solution of my problem. and what can i do?

1854


how to make a scientific calculater ?

1769


What is difference between %d and %i in c?

879


Here is a neat trick for checking whether two strings are equal

769


What are the functions to open and close the file in c language?

783