abhas Active member
| Subject: Algorithm to display a 3 digit number in words [ISC] Wed Nov 25, 2009 7:47 pm | |
| Algorithm
- Start.
- Enter
a number, of maximum three digits. (n ß Input from user)
- Calculate
the length of ‘n’.
- If the
length is more than three, goto step 5, otherwise goto step 6.
- Print
message “"Wrong input only three digit number allowed". Goto step 27.
- Check that wherther the number is greater
or less than zero.
- If it
is greater than zero, print “Positive”, otherwise print “Negative”.
- Change
the number ‘n’ to positive by calculating its absolute value and assigning it again to ‘n’.
- Define
an array “af” containing twenty words from “zero” to “nineteen”.
- Define
an array “as” containing nine elements with first elements as null character and rest of the elements as multiples of ten from Twenty to Ninety.
- Check
if the number is less than twenty, if yes goto step 16.
- Check
if number is equal to twenty, if yes goto step 17.
- Check
if number is less than hundred, if yes goto step18
- Check
if number is equal to hundred, if yes goto step 21.
- Otherwise
goto step 22.
- Print
nth index of array “af”. Goto step 27.
- Print
“Twenty”. Goto step 27.
- Extract
last digit of “n” and store it in integer type variable “x”.
- Divide
n by 10 and store it in integer type variable y.
- Print
y-1 th index of as followed by space and x th index if af. Goto step 27.
- Print
“Hundred”. Goto step 27.
- Extract
last digit of n and store it in integer type variable ‘x’.
- Divide
n by 10 and store it in integer type variable ‘y’.
- Extract
last digit of y and store it in variable ‘z’.
- Divide
y by 10 and store it in variable ‘p’.
- Print
p th index of af followed by “hundred” followed by z-1 th index of as followed by x th index of af. Goto step 27.
- Stop.
|
|