0
How write a c program to input integer and display its constitution digital from right to left in english words ?
8 Réponses
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.
+ 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
0
I wrote the code using switch till tha taking names of the numbers but i couldnt reverse the names
0
narthana wickramasinghe
Can you please post the code here?
0
Yes sure
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 ");
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.
0
Okkk I will recode and show you