成人快手

Algorithms - EdexcelSequence

Algorithms are step-by-step plans for solving problems. Algorithms can be designed using pseudo-code, flowcharts, written descriptions and program code. There are also some standard algorithms for searching and sorting.

Part of Computer SciencePrinciples of computer science

Sequence

is the first programming construct. In programming, are executed one after another. Sequence is the order in which the instructions are executed.

The sequence of instructions is extremely important as carrying out instructions in the wrong order results in a program performing incorrectly.

An explanation of sequencing, as used in algorithms and programming

In this , designed to find the average of two whole numbers, the instructions are in in the wrong sequence:

SET total TO 0
                    SET average TO number1/number2
                    SEND 鈥楨nter the first number: 鈥 TO DISPLAY
                    RECEIVE number1 FROM (INTEGER) KEYBOARD
                    SEND 鈥楨nter the second number: 鈥 TO DISPLAY
                    RECEIVE number2 FROM (INTEGER) KEYBOARD
                    SEND 鈥楾he average is 鈥 & average TO DISPLAY

Running this program would result in an error because it tries to calculate the average before it knows the values of the numbers.

This version has the instructions in the correct sequence:

SET total TO 0
                    SEND 鈥楨nter the first number: 鈥 TO DISPLAY
                    RECEIVE number1 FROM (INTEGER) KEYBOARD
                    SEND 鈥楨nter the second number: 鈥 TO DISPLAY
                    RECEIVE number2 FROM (INTEGER) KEYBOARD
                    SET average TO number1/number2
                    SEND 鈥楾he average is 鈥 & average TO DISPLAY

Writing instructions in the wrong order is one of the most common programming errors. It happens no matter which is used.