Write a C program that converts numbers to words. For example, 895
results in "eight nine five.
Answers
Answer:
Edhhhdiiwdwxxwwxomqdjjfjffgonnonc
Explanation:
Ijhpddee
Answer:
#include <stdio.h>
int main(){
int n, number = 0;
printf("Enter any number to print in words: ");
scanf("%d", &n);
while(n != 0){
number = (number * 10) + (n % 10);
n /= 10;
}
while(number != 0){
switch(number % 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 ");
break;
}
number = number / 10;
}
return 0;
}
Explanation:
First we have taken a number n as an input from the user. Then we have stored the reverse of n into a variable called number. Then we extract the last digit of the number and print the corresponding digits in words using switch case until the number becomes 0. So when we give the input 895 to the program it gives the output Eight Nine Five.
Output: 895
Eight Nine Five
#SPJ2