EE312 - Lecture 5
Announcements
•
Assignment 1 due today before midnight
•
Assignment 2 out next week
•
Topics for today will address:
– algorithms
– conditionals in decision making statements
– Program control statements (Ch. 5 & 6)
Program control logic
•
More complex problems require the ability of
a program to contain situational decision logic
that provides for alternative paths of
execution:
1. Instructions done in sequence (what we have seen so
far) can be grouped
2. Selection among alternative paths of execution
3. Iteration/repetition of a set of instructions
•
C has several types of statements for
implementing these capabilities
•
But first we need to understand these at the
program design level
Introduction to Problem
Solving and Algorithms
Programs are made of
Algorithms
(implemented as
functions in C)
and
Data Structures
(implemented as
variables, arrays, etc.)
What is an Algorithm?
•
An algorithm
is a procedure (i.e. a sequence of
steps/instructions) for solving a given problem. It must be
correct, complete, unambiguous, terminating, capable of
being “executed”(by the execution agent) and
understandable.
•
A given problem may be solvable by a number of different
algorithms. Its importance is crucial in figuring out a
solution procedure.
•
An algorithm may be transformed into a working program if
its computable
•
An algorithm will typically use levels of abstraction to make
the solution clearer and implementation easier.
•
An algorithm may be represented in several ways:
–
Pseudocode
- structured English language used to help design an algorithm (free form;
e.g. recipe)
–
Flowchart
- a graphical representation of an algorithm.
It shows control and data flow.
–
Formal languages
- outside the scope of this course
How To Shampoo Your Hair
1)
Wet your hair
2)
Apply shampoo
3) Lather
4) Rinse
5) Repeat
Follow these simple steps:
Found on the back
of a
shampoo bottle - circa 1965
How To Shampoo Your Hair
1)
Wet your hair
2)
Apply shampoo
3) Lather
4) Rinse
5) Repeat
Follow these simple steps:
Steps 1 - 4 depict a sequential flow of instructions
Step 5 introduces the notion of repetition/iteration of instructions

This ** preview** has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*