We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,973 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Pseudocode

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!

5
Contributors
4
Replies
4 Months
Discussion Span
10 Months Ago
Last Updated
6
Views
armydad1
Newbie Poster
1 post since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

DeanMSands3
Posting Whiz
310 posts since Jan 2012
Reputation Points: 80
Solved Threads: 42
Skill Endorsements: 1

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

WaltP
Posting Sage w/ dash of thyme
Team Colleague
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37

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

i = lastitem...firstitem
tungnk1993
Junior Poster in Training
95 posts since May 2010
Reputation Points: 6
Solved Threads: 7
Skill Endorsements: 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

-VLV-
Newbie Poster
9 posts since Apr 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0736 seconds using 2.67MB