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 difference between a function and a method in c?

549


How can I discover how many arguments a function was actually called with?

628


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

3831


What is a nested formula?

597


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

597






Write a program to check prime number in c programming?

586


What are the 5 types of organizational structures?

542


Is array a primitive data type in c?

568


What is the difference between a free-standing and a hosted environment?

634


how to write a c program to print list of fruits in alpabetical order?

1782


Explain how can type-insensitive macros be created?

564


Can we declare variables anywhere in c?

569


Is Exception handling possible in c language?

1572


How does pointer work in c?

608


What is a substring in c?

579