Lecture Note: Week 1
Lecture Note: Week 1
WEEK 1
Developing an Algorithm
Steeping
This is where all the instructions needed to solve our problem are set out one after to
another. Here is an example
STEP 1: START
Looping
Repeat an instruction or a set of instructions a number of times. In this case use loops
This type of loop keeps carrying out a command a command UNTIL a given
condition is satisfied. The condition is given with the UNTIL command. Here is an
example
STEP 1: START
STEP 2: INITILIZE NUM TO 1
STEP3: REPEAT
STEP 4: PRINT HELLO
STEP 5: UNTIL THE NUM IS NOT FIVE
STEP 6: STOP
In this type of loop the condition is given along with the WHILE command and end
with END WHILE command. Here is an example
STEP 1: START
STEP 2: FOR NUMBER=10 TO 20
STEP 3: PRINT NUMBER
STEP 4: END FOR
STEP 5: STOP
Choosing
This method is used to take decision. This technique is called choosing, and uses
the commands IF, THEN and ELSE.
This type of command a condition is given in the IF command followed by an action to
be taken. If the condition if satisfied follow it by THEN command. Here is an example
STEP 1: START
STEP 2: IF IT IS WEEKDAY AND IT IS NOT A HOLYDAY
STEP 3: THEN GO TO SCHOOL
STEP 4: ELSE STAY AT HOME
STEP 5: STOP
A flowchart helps to clarify how things are currently working and how they could be
improved.
Flowcharts use special symbol shapes to represent different types of actions or steps in
a process. Lines and arrows show the sequence of the steps, and the relationships among
them.
(Flow Line): Flow lines are used to connect symbols. These lines indicate
sequence of steps and the direction of flow.
Read value a,
b,c,d,e Input T (in C)
Avg=(a+b+c+d+e)/5 F=1.8*C+32
Display F
Display Avg
End
End
NO
3. Repetition: Where the logic can repeat in a loop, that is, where a sequence of
steps is repeated until the desired output is obtained. The while process allow for
the representation of a conditional loop structure within a program.
Example: Draw a flowchart to find the sum 20 even numbers natural numbers
1. Machine language
2. Assembly language
3. High-level languages
READ num1
READ num2
LOAD num1
ADD num2
STORE sum
PRINT sum
STOP
Assembled languages:
• Assembler: a program used to translate Assembly language programs.
• Produces one line of binary code per original program statement.
– The entire program is assembled before the program is sent to the
computer for execution.
Interpreted Languages:
• Interpreter: A program used to translate high-level programs.
• Translates one line of the program into binary code at a time:
– An instruction is fetched from the original source code.
– The Interpreter checks the single instruction for errors. (If an error
is found, translation and execution ceases. Otherwise…)
– The instruction is translated into binary code.
– The binary coded instruction is executed.
– The fetch and execute process repeats for the entire program.
Compiled languages:
• Compiler: a program used to translate high-level programs.
• Translates the entire program into binary code before anything is sent to
the CPU for execution.
– The translation process for a compiled program:
• First, the Compiler checks the entire program for syntax errors in the
original source code.
• Next, it translates all of the instructions into binary code.
» Two versions of the same program exist: the original source code version,
and the binary code version (object code).
• Last, the CPU attempts execution only after the programmer requests that
the program be executed.