1.11M Members

Pseudocode

 
0
 

Hello all, I am trying to design the logic for a program that allows a user to enter 10 numbers, then displays them in the reverse order of their entry. This is in pseudocode.

Thanks for your suggestions!

 
0
 

Are you familiar with stacks?
A stack is a data structure that is accessed only by it's last element.
The simplest stack is made with an array and a "top" index.
When you start, you can set the top index to zero.
To add data to the stack, you "push" it on.
To push, you simply do this:

function push(data)
    if top>stack.size
        stack[top]=data
        top=top+1
    end if
end function

To get data from a stack, you pop it.

function pop()
    if top>0
        top=top-1
        return stack[top]
    end if
end function

So what you do is push ten values, then pop them back. Try it.

 
0
 

Store them in an array and when done output the array starting from the last input.

 
0
 

For pseudocode you dont have to write in any specific programming language. Just write for example :

i = lastitem...firstitem
 
0
 

!Comment
...

Declare an Array with the size of 10
Declare a variable, Var1

!A loop for the input

For Var1=1,10,1 !(For Start_Value,End_Value,Step)

...Receive the Input and store it in the Array, in the position of the Var1

End For

For Var1=10,1,-1 !(Invert the order...)

...Print the values previously stored in the array, in the position of the Var1

End For

!And that's it!

_____________

In Fortran it would look like this (not 100% accurate, but if u know Fortran u'll get the point, xD):

Real :: Var1, Array(10)

For Var1=1,10,1
    Read*, Array(Var1)
    End For
For Var1=10,1,-1
    Print*, Array(Var1)
    End For

Hope it Helps
VLV

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article