Number To Word Conversion
2 min readMay 25, 2023
ALGORITHM:
- Prompt the user to enter a number and store it in a variable
n
. - Initialize a variable
newnum
to 0. - Repeat the following steps until
n
becomes 0:
- Calculate the remainder of
n
divided by 10 and store it in a variableremainder
. - Multiply
newnum
by 10 and add the value ofremainder
to it, updating the value ofnewnum
. - Divide
n
by 10 using integer division to remove the last digit.
4. Repeat the following steps until newnum
becomes 0:
- Calculate the remainder of
newnum
divided by 10 and store it in a variablenum
. - Check the value of
num
and perform the corresponding action: - If
num
is equal to 1, print "one". - Elif
num
is equal to 2, print "two". - Elif
num
is equal to 3, print "three". - Elif
num
is equal to 4, print "four". - Elif
num
is equal to 5, print "five". - Elif
num
is equal to 6, print "six". - Elif
num
is equal to 7, print "seven". - Elif
num
is equal to 8, print "eight". - Elif
num
is equal to 9, print "nine". - Else print”Zero”
- Divide
newnum
by 10 using integer division to remove the last digit.
CONCLUSION:
This algorithm takes the input number n
and reverses it by extracting the last digit and appending it to newnum
. Then, it iterates over each digit of newnum
and prints the corresponding word for each digit using a series of conditional statements.
FLOWCHART: