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 difference between a function and a method in c?
How can I discover how many arguments a function was actually called with?
Write a client and server program in C language using UDP, where client program interact with the Server as given below: i) The client begins by sending a request to send a string of 8 characters or series of 7 numbers, the server sends back a characters or numbers as per the request of the client. ii) In case of series of 7 numbers: The client sends a multiplication of numbers, to the server. iii) In case of a string of 8 characters: The client sends a reverse order of string to the server.. iv) Server will send an acknowledgment to the client after receiving the correct answer
What is a nested formula?
Explain what is the difference between functions getch() and getche()?
Write a program to check prime number in c programming?
What are the 5 types of organizational structures?
Is array a primitive data type in c?
What is the difference between a free-standing and a hosted environment?
how to write a c program to print list of fruits in alpabetical order?
Explain how can type-insensitive macros be created?
Can we declare variables anywhere in c?
Is Exception handling possible in c language?
How does pointer work in c?
What is a substring in c?