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
What is the maximum no. of arguments that can be given in a command line in C.?
What is a pointer variable in c language?
Explain the use of 'auto' keyword in c programming?
What is #define used for in c?
What is #define?
Explain enumerated types in c language?
What is the use of function in c?
How many bytes is a struct in c?
Explain how do you sort filenames in a directory?
What is variable declaration and definition in c?
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.
What are different storage class specifiers in c?
What does %d do in c?
What are pragmas and what are they good for?
What is data type long in c?