Introduction To Algorith and Programming
Introduction To Algorith and Programming
Programming
Week 1
Session 2
Introduction to Algorithm & Programming
Sub Topics
Introduction to Algorithm & Programming
• Algorithm Definition
• Algorithm Development Steps
• Pseudo-code
• Flow Chart Structured Theorem
• History of C
ALGORITHM DEFINITION
Algorithm Definition
• Algorithm is a procedure for solving a problem in terms
of the actions to be executed, and the order in which
these actions are to be executed
• Example:
Read bilangan
Get tax_code
Baca students_name
Basic Computer Operation: Output
• Example:
Print “Bina Nusantara University”
Write “Algorithm and Programming”
Output Total
Basic Computer Operation: Compute
• Example:
Add number to total
Total = Total + number
Basic Computer Operation: Storing
Value to An Identifier (Store)
• There are three ways of storing value into a variable:
– Initializing value using statement Initialize or
Set
– Storing value as calculation result using =
– To simply store a value into a variable using “Save”
or Store
• Example:
Set Counter to 0
Total = Price * Qty
Basic Computer Operation: Compare
• Example:
DOWHILE number < 5
print number
number = number +1
ENDDO
Pseudo-code Example 1
Example : Algorithm using a calculator
Start
Set the calculator ON
Empty any values
Do
Input price
Push plus button (+)
while all prices have been input
print total price
turn OFF calculator
End
Pseudo-code Example 2
Example : Algorithm Class Average
Start
Set total to zero
Set grade counter to one
While grade counter is less than or equal to ten
Input the next grade
Add the grade into the total
Add one to the grade counter
Set the class average to the total divided by ten
Print the class average.
End
FLOW CHART STRUCTURED
THEOREM
Flow Chart Definition
• Show logic of an algorithm
Start
Input a,b,c
d = b^2 – 4ac
Y
d<0
T
Print: x1, x2
Stop
Flow Chart : Selection (if)
false true
condition
statements
false true
condition
statements 2 statements 1
exp1
exp3
statements
true
exp2
false
statements
condition
true
false
statements
true
condition
false
• Example :
Print “Number of students:”
Set total to 49
Print “Add new student:”
Read newStudent
total = total + newStudent
Print “Number of students:”
Print total
• Description
Sequence of command is from the 1st line to the end of code. If
newStudent input is 2 then total that later on printed out is 51
Structure Theorem :
Selection
• Selection control structure is structure that allow us to choose
from several options of statement/command
• Example :
IF Day=1 THEN
Print “Monday”
ELSE
Print “Obviously not Monday”
• Description
The word “Monday” will be printed out if Day’s value equal to 1,
else it will print out the sentence “Obviously not Monday
Structure Theorem :
Repetition
• A number of statements/commands can be repeated several times
using Repetition structure control
• Example :
Stars = 0
DOWHILE Stars < 5
Print Stars
Stars = Stars + 1
ENDDO
• Description
At first Stars’ value equals to 0, after following the DOWHILE
Looping Stars’ value will be updated 5 times resulting:
01234
HISTORY OF C
History of C
• C evolved from two previous languages, BCPL and B.BCPL was developed
in 1967 by Martin Richards
• In 1970, Ken Thompson used B to create early versions of the UNIX
operating system at Bell Laboratories
• C language was evolved form B by Dennis Ritchie at Bell Laboratories
and was originally implemented on DEC PDP-11 computer in 1972
• The publication in 1978 of Kernighan and Ritchie’s book, The C
Programming Language
• 1983 X3J11 technical committee was created to make a standard of
the language
• 1989 Standard was approved
• 1999 The standard was updated
• C99 is a revised standard for the C programming language
Why Using C
• Flexibility
Close to low level machine language yet easy to
understand
• Portability
Used form micro computer to super computer