4. Introduction
Algorithm is a set of mathematical instructions or rules
that, especially if given to a computer, will help to calculate
an answer to a problem.
4
5. Example (1)
Write the algorithm and draw the flow
chart that calculate the area of a rectangle,
given the length (L) and width (w).
5
Algorithm:
Step 1 : input first number
Step 2 : input second number
Step 3 : multiply two numbers and
store result in Area
Step 4 : print Area
6. Example (2)
Write the algorithm and draw the flow chart that Determine the state of a
student (failed or succeeded) depending on his/her score in the exam
(full mark is assumed to be 100).
6
Algorithm:
Step 1 : input the score
Step 2 : check if the score is less
than 50 if yes go to Step 3
else go to Step 4
Step 3 : print Failed
Step 4 : print Succeeded
7. Example (3)
Write the algorithm and draw the flow chart that Print Numbers from 1
to 100
7
Algorithm:
Step 1 : take an initial number i=1
Step 2 : print the i
Step 3 : add 1 to i
Step 4 : check if i is less than or
equal 100 if yes go to Step
2 else stop
8. Required
• Write the algorithm and draw the flow chart that
print odd numbers from 1 to 100
• Write the algorithm and draw the flow chart that
print a sequence of numbers and their squares,
starting from one to M where M is an input.
8
11. Evolution
To write a program for a computer, we must use a
computer language.
A computer language is a set of predefined words that
are combined into a program according to predefined
rules (syntax).
Over the years, computer languages have evolved from
machine language to assembly languages to high-level
languages.
11
12. Programming Language
Programming language: A set of rules, words, symbols, and
codes used to write computer programs
To write a program, you need appropriate software for the
programming language you will be using
12
13. Categories of programming languages
Low-level languages: Difficult to code in; machine dependent
Machine language: 1s and 0s
Assembly language: Includes some names and other
symbols to replace some of the 1s and 0s in machine
language
High-level languages: Closer to natural languages
Machine independent
Visual or graphical languages: Use graphical interface to
create programs
Fourth-generation languages (4GLs): Even closer to natural
languages and easier to work with than high-level
Declarative rather than procedural
Includes structured query language (SQL) used with
databases
13