1,105,395 Community Members


Member Avatar
Newbie Poster
1 post since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 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!

Member Avatar
Posting Whiz
358 posts since Jan 2012
Reputation Points: 57 [?]
Q&As Helped to Solve: 49 [?]
Skill Endorsements: 2 [?]

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
    end if
end function

To get data from a stack, you pop it.

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

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

Member Avatar
Posting Sage w/ dash of thyme
9,363 posts since May 2006
Reputation Points: 2,905 [?]
Q&As Helped to Solve: 1,151 [?]
Skill Endorsements: 45 [?]
Team Colleague

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

Member Avatar
Junior Poster in Training
95 posts since May 2010
Reputation Points: -4 [?]
Q&As Helped to Solve: 9 [?]
Skill Endorsements: 0 [?]

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

i = lastitem...firstitem
Member Avatar
Newbie Poster
9 posts since Apr 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]


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

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