Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Program design
CT018-3-1 Introduction To C Programming Program Design
Topic & Structure of the lesson
In this chapter you will learn about:
Problem Solving
Algorithm
Pseudocodes
Flowcharts
CT018-3-1 Introduction To C Programming Program Design
Learning Outcomes
If you have mastered this topic, you should be able
to use the following terms correctly in your
assignments:
Algorithm
Pseudocode
Flowchart
CT018-3-1 Introduction To C Programming Program Design
Problem Solving
First:
ou have to
understand
the problem!
U!"#ST$!I% T&" P#O'L"(
"hat is the un#nown$ "hat are the data$
"hat is the condition$
Is it possible to satisfy the condition$Is the
condition sufficient to determine the
un#nown$%r is it sufficient$%r &edundant$
%r Contradictory$
'raw a figure!Introduce suitable
notation!Separate the various parts of the
condition!Can you write them down$
CT018-3-1 Introduction To C Programming Program Design
Problem Solving
Second:
Find the connection
between the data and
the un#nown!
Au(iliary problems
may be devised if
needed!
ou should obtain
eventually a plan of
the solution!
!")ISI% $ PL$
)ave you seen it before$ %r have you
seen the same problem in slightly different
form$
'o you #now a related problem$
*oo# at the un#nown+ ,ry to thin# of a
familiar problem having the same or similar
un#nown! Split the problem into smaller,
simple sub-problems! If you cannot solve
the proposed problem try to solve first
some related problem! %r solve more
general problem! %r special case of the
problem! %r solve the part of the problem!
CT018-3-1 Introduction To C Programming Program Design
Problem Solving
,hird:
Carry out your
plan!
*$##+I% OUT T&" PL$
Carrying out your plan of the solution,chec#
each step! Can you see clearly that step is
correct$ Can you prove that it is correct$
Fourth:
.(amine the
solution
obtained!
LOO,I% '$*,
Can you chec# the result$ Can you derive
the result differently$ Can you use the
result, or the method, for some other
problem$
CT018-3-1 Introduction To C Programming Program Design
$lgorithm
Algorithmic problem:
Any problem whose solution can be
e(pressed as a set of e(ecutable instructions!
Algorithm:
A well defined computational procedure
consisting of a set of instructions, that ta#es
some value or set of values, as input, and
produces some value or set of values, as
output.
CT018-3-1 Introduction To C Programming Program Design
*haracteristics of an $lgorithm
.ach step of an algorithm must be e(act, preciously
and ambiguously described!
It must terminate, i!e! it contains a finite number of
steps!
It must be effective, i!e!!, produce the correct output!
It must be general, i!e!! to solve every instance of the
problem! An Algorithm is implemented in some
programming language.
program = Algorithm + Data Structures.
CT018-3-1 Introduction To C Programming Program Design
Problem Solving
Slide 26 (of 80)
/ow that we have an exact idea about how the
problem is solved, let us represent this in a clearer
manner, using the defining diagram!
Input Processing %utput
0alue1
0alue2
Sum
CT018-3-1 Introduction To C Programming Program Design
Problem Solving
Slide 2 (of 80)
,he ne(t step is to identify the actual processing
steps re3uired to convert the input to become the
output!
Input Processing %utput
0alue1
0alue2
Sum 14 &ead 0alue1, 0alue2
24 Calculate Sum
54 'isplay Sum
CT018-3-1 Introduction To C Programming Program Design
$lgorithm !evelopment
Slide 28 (of 80)
%nce the defining diagram has been
developed, the ne(t logical step is to develop
the algorithm 6which is much more detailed4!
Input Processing %utput
0alue1
0alue2
Sum 14 &ead 0alue1, 0alue2
24 Calculate Sum
54 'isplay Sum
,he developed processing steps have to be more
detailed in the algorithm!
CT018-3-1 Introduction To C Programming Program Design
Operators
Slide 2! (of 80)
,he basic mathematical operators used in algorithms
are as follows:-
7 addition
- subtraction
8 multiplication
9 division
: assignment
6 4 brac#ets for grouping calculations
CT018-3-1 Introduction To C Programming Program Design
$lgorithm !evelopment
Slide 30 (of 80)
.(ample of an algorithm 6using pseudocodes4 which
can be used to carry out the tas#s outlined in the
defining diagram is as follows:-
14 &ead 0alue1, 0alue2
24 Calculate
Sum : 0alue1 7 0alue2
54 'isplay Sum
CT018-3-1 Introduction To C Programming Program Design
Pseudocoding
Slide 31 (of 80)
A Pseudocode language is semiformal, .nglish-li#e
language with a limited vocabulary that can be used
to design and describe algorithms!
,he pseudocode language can be used for:
'esigning algorithms