Algorithm / pseudo code

Pseudocode is a method of describing computer algorithms using a combination of natural language and programming language.  It is essentially an intermittent step towards the development of the actual code.  It allows the programmer to formulate their thoughts on the organization and sequence of a computer algorithm without the need for actually following the exact coding syntax.  Although pseudocode is frequently used there are no set of rules for its exact implementation.  In general, here are some rules that are frequently followed when writing pseudocode:
  • The usual Fortran symobols are used for arithmetic operations (+, -, *, / , **).
  • Symbolic names are used to indicate the quantities being processed.
  • Certain Fortran keywords can be used, such as PRINT, WRITE, READ, etc.
  • Indentation should be used to indicate branches and loops of instruction.



Here is an example problem, including a flowchart, pseudocode, and the final Fortran 90 program.  This problem and solution are from Nyhoff, pg 206:

For a given value, Limit, what is the smallest positive integer Number for which the sum
    Sum = 1 + 2 + ... + Number
is greater than Limit.  What is the value for this Sum?
Pseudocode:

    Input:    An integer Limit 

    Ouput:   Two integers: Number and Sum


1.  Enter Limit 

2.  Set Number = 0. 
3.  Set Sum = 0. 
4.  Repeat the following: 
    a.  If Sum Limit, terminate the repitition, otherwise. 
    b.  Increment Number by one. 
    c.  Add Number to Sum and set equal to Sum
5.  Print Number and Sum.

Flowchart:

No comments:

Post a Comment