How write a c program to input integer and display its constitution digital from right to left in english words ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How write a c program to input integer and display its constitution digital from right to left in english words ?

5th Jul 2020, 2:23 PM
narthana wickramasinghe
narthana wickramasinghe - avatar
8 Answers
0
narthana wickramasinghe As I understand your question, it should give the binary output but in words? Like Input: 2 //10 in binary Output: zero one By the way please try on your own first. If you are stuck at something then ask for help.
5th Jul 2020, 3:00 PM
Hanuma Ukkadapu
Hanuma Ukkadapu - avatar
+ 2
Please try to solve your task yourself first. If you should fail, show us your attempt. https://www.sololearn.com/discuss/1316935/?ref=app
5th Jul 2020, 2:57 PM
HonFu
HonFu - avatar
0
I wrote the code using switch till tha taking names of the numbers but i couldnt reverse the names
6th Jul 2020, 1:03 AM
narthana wickramasinghe
narthana wickramasinghe - avatar
0
narthana wickramasinghe Can you please post the code here?
6th Jul 2020, 1:48 AM
Hanuma Ukkadapu
Hanuma Ukkadapu - avatar
0
Yes sure
6th Jul 2020, 1:49 AM
narthana wickramasinghe
narthana wickramasinghe - avatar
0
#include <stdio.h> int main() { int n, num = 0; printf("Enter any number to print in words: "); scanf("%d", &n); while(n != 0) { num = (num * 10) + (n % 10); n /= 10; } while(num != 0) { switch(num % 10) { case 0: printf("Zero "); break; 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 ");
6th Jul 2020, 1:56 AM
narthana wickramasinghe
narthana wickramasinghe - avatar
0
narthana wickramasinghe In the switch statement, you are just getting the value of integer (num%10) and printing it. But as num is not equal to zero, the while loop keeps on printing the value of num You need to make num zero after printing i.e. just after the switch statement ----- while(num!=0){ switch(num % 10){ /* Some code here */ } num /= 10; } ------- Now as num is now zero, while loop will stop executing.
6th Jul 2020, 2:11 AM
Hanuma Ukkadapu
Hanuma Ukkadapu - avatar
0
Okkk I will recode and show you
6th Jul 2020, 2:23 AM
narthana wickramasinghe
narthana wickramasinghe - avatar