C/how can i extract them?
-------------------------
...
Expert: Narendra - 10/27/2004
Questionhow can i extract them?
-------------------------
Followup To
Question -
How can i program in C so that somone inputs a number and it displays the number in words?
ie.
Input Number : 510
Output Five Hundred and Ten
Answer -
Extract the digits and not their place value and then print that.
Same way as you mentally read a number.
-ssnkumar
AnswerUse % operator to extract the digits.
For example, take the number 4582.
4582 % 10 = 2 (Digit# 1)
4582 / 10 = 458
458 % 10 = 8 (Digit# 2)
458 / 10 = 45
45 % 10 = 5 (Digit# 3)
45 / 10 = 4
4 % 10 = 4 (Digit# 4)
Since there are only 4 digits, it makes a thousand.
So, the last digit (Digit# 4) tells that it is "Four Thousand".
The previous digit is of a hundred. So, Digit# 3 tells that it is "Five Hundred".
Previous to that is of a Ten. So, Digit# 2 tells that it is "Eighty".
The last digit is "Two".
Combine all these and you will get:
4582 = "Four Thousand Five Hundred and Eighty Two".
Hope this helps.....
-ssnkumar