Problem_Solving_class
Problem_Solving_class
What is an Algorithm
An algorithm is a set of instructions that if when
followed in a sequence will lead to a solution for the
problem.
Characteristics of Algorithm
1. Must be precise 4. Must pass the flow of
control
2. Must be unambiguous from one process to
another.
3. Eventually terminate
Test and Validate the solution
This is the final step. This is where you see if
the
problem works in other word if it is solve. One
way of test is by using a flow chart.
Example 1
Add two number and find their sum
solutio
n
Input Process Output
Num 1 Sum=num1+ sum
Num 2 num 2
Constants and Variables
⚫Program data are like ingredients in a recipe,
must be stored in a suitable container.
⚫Constants is a data item with a name and
value that remains the same during the
execution of a program .
Eg. Pie = 3.14
END.
Read/Readln
⚫The READ and READLN instructions read a
variable from the keyboard. The command
will continue to read until ENTER is pressed
(with an exception). In contrast
with READ, READLN reads the variable and,
when the user pressed ENTER, it moves the
cursor on the next line.
⚫These instructions can read one variable or
more variables. For example:
Read two numbers and find their sum. Print their sum
Algorithm Pascal
Algorithm Cal Program Cal;
Var num1,num2,sum:integer Var num1,num2,sum:integer;
Start Begin
Output(‘Please enter a number’) Writeln (‘Please enter a number’);
Read(num1) Readln(num1);
readln;
end.
Terms to know
⚫ Low level languages – Generation 1 and 2
⚫ High level languages – Generation 3 to 5
⚫ Source code – This is a sequence of statement in a
programming language.
⚫ Translator – is a system program that converts a program
written in the source code to machine code.
⚫ Compiler- is a system program that processes all the line of
code in an entire program.
⚫ Object code – This contains the machine instruction for
executable program and is used to create the finish
executable program in another process called linking.
⚫Interpreter – is a translator of a high level
programming language that translate and run
the program at the same time.
Write a an array to read ten numbers and calculate their sum. Print sum.
Program summm;
var
num:array[1..2] of integer;
sum, x: integer;
begin
Writeln('Let us write our first array');
for x:= 1 to 2 do begin
Writeln('Plese enter a number');
Readln(num[x]);