Vous êtes sur la page 1sur 18

PSEUDOCODE,

ALGORITHM AND
FLOWCHART
Submitted to:
Prof !er"i#e Ab$d
Submitted b%:
GROUP 1
Alcantara, Ma. Rhima G.
Calonia, Abigail Bernadette S.
Lopez, Mareanne A.
Maglaya, Mitzi S.
Palma, Camille Aira P.
Tee, Andrea May B.
Villaranca, Rachell M.
T$b&e of Co"te"t'
Pseudocode, Algorithm and Flowchart
!. Algorithm and "lo#chart
a. Algorithm
b. "lo#chart
!!. "lo#charting Symbol$
!!!. R%le$ in "lo#charting
!V. &'ample$ o Algorithm and "lo#chart
V. (!)then)el$e* Statement
V!. ("or)to)$tep* Statement
V!!. (+e't* Statement
V!!!. +e$ted)!
!,. P$e%docode
!. A&(orit)m $"d F&o*#)$rt
$ A&(orit)m
Algorithm i$ a li$t o in$tr%ction$ or carrying o%t $ome proce$$
$tep by $tep. Algorithm$ e'ec%ted by a comp%ter can combine
million$ o elementary $tep$ $%ch a$ addition$ and $%btraction, into
a mathematical calc%lation. -hen #e get to mathematical
algorithm$, #e #ill ha.e to be m%ch more preci$e.
&'ample/
0o# to brea1 the Ca$ano.a2$ heart3
0o# to ma1e Graham Ball$3
4. !n a mi'ing bo#l, combine cr%$hed graham,
conden$ed mil1, e.aporated mil1 and
cinnamon po#der then mi' #ell.
5. Scoop a $poon%l o mi't%re then mold into
a ball $hape$ and roll in $prin1le$.
Place into paper c%p$ then rerigerate or at lea$t 6 ho%r$ beore
$er.ing.
b F&o*#)$rt
A diagram repre$enting the logical $e7%ence in #hich
combination o $tep$ or operation i$ to be perormed. The mo$t
#idely %$ed graphic method or de$cribing comp%ter operation$.
Ma8or 9$e$ o "lo#chart
4. A$ a documentation tool : a ;o#chart aid$ in
comm%nicating the nat%re o the operation.
5. !n program development the programmer %$e$
;o#charting in and thro%gh e.ery part o hi$ ta$1 to/
a. Mar$hall and organize hi$ act$ on paper
b. <%tline problem$, logic and $ol%tion$
c. =eal $y$tematically #ith the problem a$ a
#hole
d. B%ild, $tep by $tep, hi$ o#n reerence
doc%mentation and reminder$
To a programmer, a ;o#chart
a. "lo#chart i$ a 1ind o all p%rpo$e tool
b. (BL9&PR!+T* o a program
c. Mean$ o e'perimenting #ith .ario%$
approache$
d. Laying o%t the logic
e. "lo#chart i$ .al%able beca%$e it $ho#$ a lot at
a glance
. "lo#chart help$ %$ to $ee relation$hip #hich #e
had not pre.io%$ly ob$er.ed and o%r o.er)all
logical thin1ing i$ greatly impro.ed by
;o#chart$.
g. 9$e$ the ;o#chart a$ hi$ g%ide or coding
h. Vi$%al repre$entation o an algorithm
&'ample/
!!. F&o*#)$rti"( S%mbo&'
$ !np%t><%tp%t Symbol : repre$ent$ an in$tr%ction to an
inp%t>o%tp%t de.ice
b Proce$$ing Symbol : repre$ent$ gro%p o program in$tr%ction$
that perorm proce$$ing %nction o the program $%ch a$
arithmetic operation$, compare ? $ort
# =eci$ion Symbol : denote$ a point in program #here more than
one path can be ta1en@ %$ed to doc%ment point$ in the program
#here alternati.e path$ i$ po$$ible
d Preparation Symbol : repre$ent$ an in$tr%ction that #ill alter
program2$ co%r$e o e'ec%tion
e Terminal Symbol : de$ignate$ the beginning and the end o a
program@ %$ed in $peciying error condition$, $%ch a$ parity error
chec1$ or detection o in.alid character$
f PredeAned Proce$$ Symbol : repre$ent$ programmed $tep not
e'plicitly detailed in the program ;o#chart@ %$ed #hen a
proced%re need$ to be repeated $e.eral time$
( <n)page Connector : %$ed to connect one part o a ;o#chart to
another #>o dra#ing ;o#line$@ denote$ an entry or an e'it rom
another part o the ;o#chart@ %$ed to change the reading
$e7%ence o a ;o#chart on the $ame page@ aid$ in de.eloping a
clearer, better, organized, $impliAed ;o#chart
) "lo# =irection !ndicator$ : $ho# the direction o proce$$ing or
data ;o#
i <B)page Connector : %$ed to de$ignate entry to or e'it rom a
page #hen a ;o#chart re7%ire$ more than one page@ %$ed in
comple' ;o#chart$ #>c oten re7%ire detailed diagram
+ "lo# Line$ : $ho# $e7%ence in #>c ;o#chart $ymbol$ are to be
read@ indicate an arro#head i the logic ;o# i$ rom right to let
or rom bottom to top@ i the logic ;o# i$ rom top to bottom or
rom let to right, arro#head i$n2t re7%ired
!!!. Ru&e' i" F&o*#)$rti"(
$ 9$e only one $tart and one $top per ;o#chart.
b The logic ;o# o the $ol%tion i$ di$played rom top to bottom and
rom let to right.
# 9$e the appropriate $ymbol or each type o operation.
d 9$e connector$ #hen mo.ing to another part o the ;o#chart
rather than line$.
e C%e$tion$ in ;o#chart$ are a$1ed in a ye$>no ormat. Complete
both the ye$ $ide and the no $ide or each 7%e$tion a$1ed in the
;o#chart.
f =o not lea.e dead)end$))that i$, a part o a 7%e$tion
%nan$#ered. Be $%re to ha.e only one $tart and only $top))that
i$, one #ay in and one #ay o%t o the ;o#chart.
!V. E,$m-&e' of A&(orit)m $"d F&o*#)$rt
$ The radi%$ o a circle i$ e7%al to one %nit. =ra# a ;o#chart to
comp%te the area o the circle and print o%t the .al%e o the
radi%$ and the area.
Algorithm/
ST&P 4. =eAne the .al%e o the Radi%$ DRE and P!.
ST&P 5. Calc%late the area o the circle, AR&A F P!GRGR.
ST&P 6. Print o%t the radi%$ and area.
"lo#chart/
b Gi.en three n%mber$ A, B, C. =ra# a ;o#chart to comp%te and
print o%t $%m, the a.erage, and the prod%ct o A, B and C.
Algorithm/
ST&P 4. Read in the .al%e$ o A, B, C. Dor inp%tE
ST&P 5. =etermine the $%m o the three .al%e$.
ST&P 6. Comp%te the a.erage by di.iding the $%m by 6.
ST&P H. Comp%te the prod%ct o the three .al%e$.
ST&P I. Print o%t the comp%ted .al%e$ D$%m, a.erage and
prod%ctE.
"lo#chart/
E N D
# The S%per +iner$ Man%act%ring Company plan$ to gi.e a year)
end bon%$ to each employee. =ra# a ;o#chart #hich #ill
comp%te the bon%$ o an employee. Con$ider the olloin criteria/
! the employeeJ$ monthly $alary i$ le$$ than 4K,KKK pe$o$, the
bon%$ i$ IKL o the $alary@ or employee$ #ith $alarie$ greater
than 4K,KKK pe$o$, the bon%$ i$ 4K,KKK. Print o%t the name and
corre$ponding bon%$ o the employee.
Algorithm/
ST&P 4. Read in the employeeJ$ name and $alary.
ST&P 5. Te$t i the employeeJ$ $alary i$ le$$ than 4K,KKK
pe$o$.
ST&P 6. ! the monthly $alary i$ le$$ than 4K,KKK pe$o$,
the bon%$ i$ IKL o the $alary. 0o#e.er, i the monthly
$alary i$ greater than 4K,KKK pe$o$, the bon%$ i$ 4K,KKK
pe$o$.
ST&P H. Print o%t the employeeJ$ name and bon%$.
"lo#chart/
E N D
d Gi.en t#o n%mber$ , and M. =ra# a ;o#chart to determine the
diBerence bet#een , and M. ! ,)M i$ negati.e, comp%te RF,NM@ i
,)M i$ zero, comp%te RF5,N5M@ and i ,)M i$ po$iti.e, comp%te
RF,GM. Print o%t the .al%e$ o ,, M and R.
Algorithm/
ST&P 4. Read in the .al%e$ o , and M.
ST&P 5. S%btract M rom ,
ST&P 6. ! the diBerence bet#een , and M i$ negati.e,
comp%te RF,NM@ i zero, comp%te RF5,N5M@ and i
po$iti.e, comp%te RF,GM.
ST&P H. Print o%t the .al%e$ o ,, M and R.
"lo#chart/
END
. /
V. 0If1t)e"1e&'e2 St$teme"t
The if1t)e"1e&'e $tatement i$ %$ed to te$t a true/false
expression and to ta1e the THEN action i the $tatement i$ TRUE
and the ELSE action i the $tatement i$ FALSE.
!t i$ compo$ed o a $tatement n%mber, ollo#ed by the
1ey#ord IF and a tr%e>al$e e'pre$$ion ollo#ed by another 1ey#ord
THEN and an action to be perormed, and ollo#ed by the la$t
1ey#ord ELSE #ith another action to be ta1en.
! the tr%e>al$e $tatement i$ true, the THEN action i$ taken
and the ELSE action i$ disregarded. The THEN action may be a
$ingle $tatement action o any type. ! the tr%e>al$e e'pre$$ion, the
ELSE action i$ taken and the THEN action i$ disregarded. A line
n%mber may be %$ed #itho%t a G< T< ollo#ing the T0&+ or &LS&.
An IF1THEN1ELSE STATEMENT can %$%ally be nested within
other IF1THEN1ELSE STATEMENT, tho%gh the logic can be tric1y
and the re$%lt$ can t%rn o%t diBerently than the programmer may
e'pect.
THE GENERAL FORM OF THE IF1THEN1ELSE
STATEMENT:
L!+& O !" tr%e>al$e $tatement T0&+ action &LS& action
!LL9STRAT!V& &,AMPL&S/
a. HK !" ,PI T0&+ QFQN5 &LS& QFQNI
b. IK !" AF4 T0&+ 4KK &LS& 4IK
c. RK !" SPK T0&+ 5KK &LS& 4K
d. TK !" =!""PK.K4 T0&+ PR!+T (SMALL* &LS& PR!+T
(LARG&*
e. UK !" BPC T0&+ G<T< VI &LS& PR!+T (BWC*
. VK !" QFDMNIE T0&+ LFI &LS& !" QFDMN4KE T0&+ LFR
V!. 0For1to1'te-2 St$teme"t
The "<R)T<)ST&P $tatement together #ith the +&,T
$tatement orm$ an alternati.e loop $o that the $e7%ence o
$tatement$ ollo#ing the "<R)T<)ST&P $tatement %p to the +&,T
$tatement are e'ec%ted o.er a $peciAed n%mber time$.
The "<R)T<)ST&P $tatement con$i$t o $tatement n%mber, the
1ey#ord "<R and a .ariable, ollo#ed by an e'pre$$ion, and the
1ey#ord$ T< and ST&P each ollo#ed by an e'pre$$ion.
Since the "<R)T<)ST&P $tatement $peciAe$ ho# time$ the
loop #ill be e'ec%ted, it m%$t al#ay$ be the Ar$t $tatement in the
loop. !ncl%ded in the Ar$t $tatement i$ a non)$%b$cripted n%meric
.ariable, called the r%nning .ariable, #ho$e .al%e change$ each
time the loop i$ determined by $peciying initial and Anal .al%e$ or
the r%nning .ariable. The r%nning .ariable i$ al#ay$ incremented by
4, each time the loop i$ repeated, %ntil the .ariable e7%al$ the Anal
.al%e. The r%nning .ariable can ho#e.er be incremented by $ome
.al%e other than 4 i de$ired. Thi$ i$ accompli$hed by adding ST&P
cla%$e to the $tatement. The initial .al%e, Anal .al%e and the
increment can be con$tant$, .ariable$ or n%meric e'pre$$ion$.
THE GENERAL FORM OF THE FOR1TO1STEP
STATEMENT:
L!+& O "<R .ariable e'pre$$ion T< e'pre$$ion ST&P
e'pre$$ion
!LL9STRAT!V& &,PR&SS!<+S/
a. 4K "<R QF4 T< 4KK
b. 5K "<R LFK T< 5I ST&P 5
c. 6K "<R +<FI T< IK ST&P I
d. HK "<R ,F4KK T< K ST&P )4K
e. IK "<R MFK.I T< 6.U ST&P K
. RK "<R XFM T< + ST&P Q
g. TK "<R AF+4 T< +5 ST&P +6
h. UK "<R "FB>5 T< DANBE Y5Z ST&P LN4
RULES APPL3 IN THE FOR1TO1STEP LOOP
a. Placement o the ST&P cla%$e i$ optional i the increment
i$ 4.
b. The r%nning .ariable may appear in a $tatement #ithin
the loop, b%t it$ .al%e m%$t and cannot be changed or
altered.
c. ! the Anal and initial .al%e$ o the r%nning .ariable are
e7%al and the $tep $ize i$ non)zero, the loop #ill be
e'ec%ted once.
d. The loop #ill not e'ec%ted %nder the ollo#ing
condition$/
4. The initial and Anal r%nning .ariable .al%e$ are e7%al
and $tep $ize i$ zero.
5. The Anal .al%e o the r%nning .ariable i$ le$$ the initial
.al%e and the $tep $ize i$ po$iti.e.
6. The Anal .al%e o the r%nning .ariable i$ greater than the
initial .al%e and the $tep $ize i$ negati.e.
e. Control can be tran$erred o%t the loop b%t not into one.
Tran$er o%t can be accompli$hed by a G<T<, !")T0&+ or
<+)G<T< $tatement.
V!!. 0Ne,t2 St$teme"t
The +&,T $tatement i$ %$ed together #ith "<R)T<)ST&P
$tatement to $et %p ad e'ec%te a program loop. X%$t a$ a loop al#ay$
begin$ #ith a "<R)T<)ST&P $tatement, it al#ay$ end$ #ith a +&,T
$tatement. The complete loop i$ compri$ed o all $tatement$ incl%ded
bet#een the "<R)T<)ST&P and the +&,T $tatement$, and any n%mber
o $tatement$ may be placed bet#een the t#o $tatement$.
!t con$i$t o a $tatement n%mber, ollo#ed by the 1ey#ord +&,T,
ollo#ed by a r%nning .ariable name. Thi$ r%nning .ariable m%$t be the
$ame a$ the r%nning .ariable that appear$ in the corre$ponding "<R)
T<)+&,T $tatement.
Any n%mber o "<R)T<)ST&P loop$ may be ne$ted. !n thi$ ca$e,
the innermo$t +&,T m%$t al#ay$ %$e the .ariable a$$ociated #ith the
innermo$t "<R)T<)ST&P and +&,T $tatement$.
The +&,T $tatement increment the loop .ariable by the ST&P
$ize, and i the .ariable ha$ not e'ceeded the Anal .al%e, control i$
ret%rned bac1 to the "<R)T<)ST&P $tatement.
Since the loop may be bro1en to G<T< or $imilar control
$tatement$ at any time, the r%nning .ariable controlling the loop may
al$o be altered in $tatement$ other than the +&,T $tatement.
THE GENERAL FORM OF THE NE4T STATEMENT
L!+& O +&,T .ariable
!LL9STRAT!V& &,AMPL&S/
a. 4IK +&,T Q
b. 4RK +&,T !
c. 4TK +&,T ,
d. 4UK +&,T +<
V!!!. Ne'ted1If
The ne$ted !" $tatement i$ a term %$ed in comp%ter
programming to reer to a $tatement that i$ in$ide another !"
$tatement . So #hen an !" $tatement ha$ another !" $tatement a$ one
o it$ po$$ible proce$$ing branche$, the$e !" $tatement$ are $aid to be
ne$ted.
(+e$ting* !" %nction increa$e$ the ;e'ibility o the %nction by
increa$ing the n%mber o po$$ible o%tcome$. Thi$ ne$ting ma1e$ it
po$$ible or a $ingle orm%la to ta1e m%ltiple deci$ion$.
Synta' o &'cel +e$ted ! orm%la/
F!"DCondition[4,Val%e[i[Tr%e[4,!"DCondition[5,Val%e[i[Tr%e[5,Val%e[i
["al$e[5EE
0ere, \Condition[42 reer$ to the condition %$ed in the Ar$t !".
\Val%e[i[Tr%e[42 #ill be the re$%lt i Ar$t !" $tatement i$ Tr%e.
\Condition[52 i$ the condition %$ed in the $econd !". The $econd !" #ill
only come into pict%e #hen the "ir$t !" $tatement re$%lt$ a "al$e .al%e.
\Val%e[i[Tr%e[52 #ill be the re$%lt i $econd !" $tatement i$ Tr%e.
\Val%e[i["al$e[52 #ill be the re$%lt i $econd !" $tatement i$ "al$e.
&'ample o +e$ted !"2$ in &'cel
E,$m-&e 5:
The company decide$ to gi.e bon%$ to it$ employee$.
Criteria are a$ ollo#$/ 5KL bon%$ to the +orth Region
&mployee$, 6KL to the So%th Region &mployee$, HKL to the &a$t
Region &mployee$ and IKL to the -e$t Region &mployee$.
!n thi$ ca$e #e can %$e &'cel +e$ted !" orm%la to And the
bon%$ or each employee. The orm%la can be/
F!"DB5F]+orth],]5KL],!"DB5F]So%th],]6KL],!"DB5F]&a$t],]HKL]
,!"DB5F]-e$t],]IKL], ]Region i$ !n.alid]EEEE
The orm%la i$ 7%ite $imple, it 8%$t chec1$ i \B52 Dcell that
contain$ region detail$ or Ar$t employeeE i$ e7%al to (+orth*,
then .al%e $ho%ld be 5KL, i not then chec1 i B5 i$ e7%al to
(So%th*, i ye$ then .al%e $ho%ld be 6KL, i not mo.e on to ne't
!" $tatement and $o on.
Similarly or the $econd employee the orm%la #o%ld be/
F!"DB6F]+orth],]5KL],!"DB6F]So%th],]6KL],!"DB6F]&a$t],]HKL]
,!"DB6F]-e$t],]IKL], ]Region i$ !n.alid]EEEE
!n ca$e the Region doe$ not match #ith any one o the !"
condition$ then the o%tp%t $ho%ld be (Region i$ !n.alid*. DA$ #e
can $ee in Ma$ato$hi2$ ca$e.E
E,$m-&e 6:
St%dent$ #ith $core$ belo# HK are con$idered a$ ("ail*, $core$ bet#een
H4 and RK are con$idered (Grade C*, $core$ bet#een R4 and TI are
con$idered (Grade B* and $core$ bet#een TR and 4KK are con$idered
a$ (Grade A*
!n the $econd e'ample #e ha.e a table o $t%dent$ and
their $core$. +o# ba$ed on their $core$ #e ha.e to gi.e a grade
to the $t%dent$.
!n thi$ $cenario #e can %$e a ne$ted ! orm%la a$/
F!"DB5PFHK,]"ail],!"DA+=DB5WFH4,B5PFRKE,]Grade
C],!"DA+=DB5WFR4,B5PFTIE,]Grade
B],!"DA+=DB5WFTR,B5PF4KKE,]Grade A]EEEE
Thi$ orm%la, again, 8%$t chec1$ i B5 Dcell containing the
$core o Ar$t $t%dentE i$ le$$ than or e7%al to HK, i tr%e then the
.al%e $ho%ld be ("ail* i not then chec1 the ne't !" condition and
$o on.
Mo% can $ee that in the inner)mo$t !" $tatement ! ha.en2t
%$ed the \Val%e[i["al$e2 #hich i$ alright $ince all $core$ all into
a choice. !n)ca$e all the !" condition$ in thi$ orm%la #ill re$%lt
into a "al$e .al%e then the orm%la #ill $imply ret%rn a \"ALS&2
1ey#ord.
!,. P'eudo#ode
P$e%docode i$ an &ngli$h)li1e pre$entation o the $tep$ needed
to $ol.e a problem. !t i$ #ritten #ith a rela'ed $ynta' that allo#$
$t%dent$ $ol.e a problem at a le.el that hide$ the detail #hile they
concentrate on the problem re7%irement$. in other #ord$, it allo#$
$t%dent$ to concentrate on the big pict%re.
!n addition to being an e'cellent de$ign tool, p$e%docode i$ al$o
lang%age independent. Con$e7%ently, $t%dent$ can %$e the $ame
p$e%docode de$ign to implement an algorithm in $e.eral diBerent
lang%age$.
"lo#chart$ #ere the Ar$t de$ign tool to be #idely %$ed, b%t
%nort%nately they do not .ery #ell re;ect $ome o the concept$ o
$tr%ct%red programming. P$e%docode, on the other hand, i$ a ne#er
tool and ha$ eat%re$ that ma1e it more re;ecti.e o the $tr%ct%red
concept$. 9nort%nately, the narrati.e pre$entation i$ not a$ ea$y to
%nder$tand and ollo#.
Ad.antage$ o P$e%docode
4. Can be done ea$ily on a #ord proce$$or
5. &a$ily modiAed
6. !mplement$ $tr%ct%red concept$ #ell
=i$ad.antage$ o P$e%docode
4. !tJ$ not .i$%al
5. There i$ no accepted $tandard, $o it .arie$ #ide rom
company to company.
0o# -e Store and Acce$$ =ata
4. R&A= Statement ) tell$ the comp%ter to get .al%e rom the
inp%t de.ice and $tore it in the name$ memory The
comp%ter $tore$ all program data into memory location$. !t
i$ perectly able to %nder$tand li1e/
R&A= 4VKUT,UKVTR,4KVH6,UKTRH
b%t #e #o%ld ha.e a hard time #ith it. $o #e name o%r
$torage location$ %$ing #ord$ that are de$cripti.e to %$/
.ariable name$ #ill $tart #ith a lo#er ca$e letter
they #ill no $pace$ in them
additional #ord$ in them #ill $tart #ith a capital
name$ m%$t be %ni7%e #ithin the program
con$i$tent %$e o name$.
5. -R!T& Statement ) i$ %$ed to di$play inormation on the
o%tp%t de.ice. To di$play #ord$, enclo$e them in 7%ote$.
6. ASS!G+M&+T Statement) %$ed #hen #e need to comp%te a
.al%e in a program.
Calc%lation Symbol$ 1 to $ymbolize$ the arithmetic operator
D E gro%ping > di.ide
GG or ^ e'ponent N add
G m%ltiply ) $%btract
Selection
-hen #e ha.e to ma1e a choice bet#een action$ #e almo$t
al#ay$ ba$e that choice on a te$t. The te$t %$e$ phra$e$ li1e ]i$
le$$ than] or ]i$ e7%al to]. There i$ a %ni.er$ally accepted $et o
$ymbol$ %$ed to repre$ent tho$e phra$e$/
W greater than PF le$$ than or
e7%al to
P le$$ than WF graeter than
or e7%al to
F e7%al to P W not e7%al to
R%le$ or P$e%docode
4 -rite only one $tatement per line.
5 Capitalize initial 1ey#ord.
6 !ndent to $ho# hierarchy.
H &nd m%ltiline $tr%ct%re$.
I Qeep $tatement$ lang%age independent.
O

Vous aimerez peut-être aussi