+ 1

Write a program in c which user enters a number like 4250 and output should be in words i.e. four thousand two hundred and fifty

I am unable to make this program. please you help me

28th Jan 2022, 5:52 AM
Nitesh Nagar
Nitesh Nagar - avatar
4 odpowiedzi
+ 3
You need to: - use a recursive function; - use the modulus operator (%); - use a switch-case structure to match each digit to its corresponding string (0-9 <=> zero-nine);
28th Jan 2022, 7:55 AM
Romeo Cojocaru
Romeo Cojocaru - avatar
+ 2
You have to traverse the number left to right, digit by digit and print it's name, along with the other name (hundred or thousand or etc...). This is a complex program, for now design it to handle numbers upto 9999. Later you can add more numbers if needed
28th Jan 2022, 6:47 AM
Rishi
Rishi - avatar
0
I think it would be better to traverse the array from least significant digit (right) to most sig. dig. (left most number). Your example would read 0, then 5 so it knows to say "and fifty" as the last words, then 2 which must be "two hundred", then 4, then nothing else, so it can start the words with "four thousand". Reading right to left is not as easy to make the correct words, especially with zeros following hundreds or tens, eg 50.
28th Jan 2022, 12:36 PM
HungryTradie
HungryTradie - avatar