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 assert and when would I use it?
how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions
Is it acceptable to declare/define a variable in a c header?
What the different types of arrays in c?
What are keywords c?
Explain which function in c can be used to append a string to another string?
Write a program to know whether the input number is an armstrong number.
You have given 2 array. You need to find whether they will
create the same BST or not.
For example:
Array1:10 5 20 15 30
Array2:10 20 15 30 5
Result: True
Array1:10 5 20 15 30
Array2:10 15 20 30 5
Result: False
One Approach is Pretty Clear by creating BST O(nlogn) then
checking two tree for identical O(N) overall O(nlogn) ..we
need there exist O(N) Time & O(1) Space also without extra
space .Algorithm ??
DevoCoder
guest
Posted 3 months ago #
#define true 1
#define false 0
int check(int a1[],int a2[],int n1,int n2)
{
int i;
//n1 size of array a1[] and n2 size of a2[]
if(n1!=n2) return false;
//n1 and n2 must be same
for(i=0;i
Explain what is the difference between far and near ?
What are different storage class specifiers in c?
Can we access the array using a pointer in c language?
Is python a c language?
c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above
What does the c preprocessor do?
What is a char c?