sequential structures

We explain the sequential structures, how they are represented in pseudocode and some practical examples of them.

The sequential structure is one in which one action (instruction) follows another in sequence. The tasks follow one another in such a way that the output of one is the input of the next and so on until the end of the process.

In Pseudocode a Sequential Structure is represented as follows:

Take a look at the following everyday problem and its respective algorithms represented in Pseudocode and flowcharts:

• I have a phone and I need to call someone but I don’t know how to do it.

The above example is a simple algorithm for an everyday problem given as a sample of a sequential structure. Now we will see the components that belong to it:

Assignment

The assignment consists of passing values ​​or results to an area of ​​memory. This zone will be recognized with the name of the variable that receives the value. The allocation can be classified as follows:

  • Simple: It consists of passing a constant value to a variable (to 15)
  • Counter: It consists of using it as a verifier of the number of times a process is performed (aa + 1)
  • Accumulator: It consists of using it as an adder in a process (aa + b)
  • Work: Where you can receive the result of a mathematical operation involving many variables (ac + b*2/4).

In general, the format to be used is the following:

The symbol should read “assign”.

Write or output data

It consists of sending a result or message through an output device (eg monitor or printer). This instruction displays the message enclosed in quotes or the content of the variable on the screen. This process is represented as follows:

See also  /faq/277.php

Reading or data entry

The reading or input of data consists of receiving from an input device (eg the keyboard) a value or data. This data will be stored in the variable that appears after the instruction. This operation is represented like this:

DECLARATION OF VARIABLES AND CONSTANTS

The declaration of variables is a process that consists of listing at the beginning of the algorithm all the variables that will be used, in addition to placing the name of the variable, it must be said what type of variable it is.

Counter: INTEGER

Age, I: WHOLE

Address : CHAIN_OF_CHARACTERS

Basic_Salary : REAL

Option : CHARACTER

In the above declaration of variables Counter, Age, and I are declared to be of integer type; Basic_Salary is a variable of type real, Option is of type character, and the variable Address is declared as an alphanumeric string variable.

At the moment of declaring constants, it must be indicated that it is constant and its respective value must be placed.

CONSTANT Pi 3.14159

CONSTANT Msg “Press a key and continue”

HEIGHT CONSTANT 40

When working with algorithms, it is generally not customary to declare variables or constants due to simplicity reasons, that is, it is not a straitjacket to declare variables. However, in this course we will do it for all the algorithms that we carry out, with this we manage to make them more understandable and organized and, incidentally, it allows us to get used to declaring them since most programming languages ​​(among them C++) require that the declarations be necessarily declared. Variables to be used in programs.

See also  Inheritance in Sass with @extend

Let’s see some examples where everything we have seen so far about algorithms is applied:

Example 1: Write an algorithm that asks for two numbers and returns the sum of these as a result. Use Pseudocode and flowchart.

Example 2: Write an algorithm that allows to know the area of ​​a triangle from the base and the height. Express the algorithm using pseudocode and flowchart.

Loading Facebook Comments ...
Loading Disqus Comments ...