Algorithms and Programming
Algorithms and Programming
Algorithms and Programming
Greater t(an or
e1ua to
Not e1ua to
Example 2 ,rite an algorithm that reads two values! determines
the largest value and prints the largest value with an identifying
message.
Agorit(m ;tep ( Input LA7ME(! LA7ME<
;tep < if VALUE1 > VALUE2
then 0AN C LA7ME(
else 0AN C LA7ME<
endif
;tep @ Print (he largest value is$. *"1
)o%c(art&
MA: = ;A(E1
P./nt
The largest value is, MAX
ST!P
" N
START
Input
;A(E1,;A(E2
MA: = ;A(E2
/4
;A(E17;A(E2
NESTED I)S
One of the alternatives within an ?$JTIENJE7;E statement
may involve further ?$JTIENJE7;E statement
Example 5 ,rite an algorithm that reads t(ree numbers and
prints the value of the largest number.
Agorit(m ;tep ( Input N(! N<! N@
;tep < if N1>N2
then if N(KN@
then 0AN C N( ON(KN<! N(KN@P
else 0AN C N@ ON@KN(KN<P
endif
else if N<KN@
then 0AN C N< ON<KN(! N<KN@P
else 0AN C N@ ON@KN<KN(P
endif
endif
;tep @ Print (he largest number is$. *"1
)o%c(art& Dra% t(e 2o%c(art o$ t(e a"ove Agorit(m3
Example 3 ,rite and algorithm and draw a Howchart to
a' read an employee name &NA0E'! overtime hours worked
&OLE>T?0E'! hours absent &A+;ENT' and
b' determine the bonus payment &%A=0ENT'.
+onus ;chedule
OLE>T?0E J
&<D@'QA+;ENT
+onus %aid
KA. hours
K@. but A. hours
K<. but @. hours
K(. but <. hours
(. hours
R2.
RA.
R@.
R<.
R(.
Agorit(m ;tep ( Input NA0E!OLE>T?0E!A+;ENT
;tep < if OLE>T?0EJ&<D@'QA+;ENT K A.
then %A=0ENT C 2.
else if OLE>T?0EJ&<D@'QA+;ENT K @.
then %A=0ENT C A.
else if OLE>T?0EJ&<D@'QA+;ENT K <.
then %A=0ENT C @.
else if OLE>T?0EJ&<D@'QA+;ENT K (.
then %A=0ENT C <.
else %A=0ENT C (.
endif
endif
endif
endif
;tep @ Print F+onus forG! NA0E Fis RG! %A=0ENT
)o%c(art& Dra% t(e 2o%c(art o$ t(e a"ove agorit(m4