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
how do you execute a c program in unix.
Why is extern used in c?
What are keywords c?
How to declare a variable?
What is printf () in c?
How can I copy just a portion of a string?
What is scope and lifetime of a variable in c?
why use "return" statement a) on executing the return statement it immediately transfers the control back to the calling program b) it returns the value present in the parentheses return, to the calling program c) a & b d) none of the above
Why do we write return 0 in c?
What is a far pointer in c?
What are different storage class specifiers in c?
How can I access an I o board directly?
How do you write a program which produces its own source code as output?
What is a const pointer in c?
How can I find the modification date of a file?