You are on page 1of 7

Flowchart exercises and examples

• What is the output, Start


if the user gives
in: a, b, c
a=3, b=9, c=5?
• What is the output, true false
a>c
if the user gives
a=5, b=2, c=7? true a>b false true b>c false

R=a R=b R=c

• What does this out: R


algorithm do?
End
7
Flowchart exercises and examples
• How do the values of x, y and s change Start
during the process, if x=5 and y=4?
in: x, y
• What is the output in this case?
• How many times will the condition s=x
evaluated?
false y>0 true
• What does this algorithm do?
• How can you modify it out: s s=s+1

to calculate the product of y=y-1


End
x and y?

8
Flowchart exercises and examples
• How do the values of x and y change Start
during the process, if the input is 10?
in: x
• What is the output, if the input is 60?
• What does this algorithm do? y=2

• Is it work, if x=1? true y<=x false


• If the input is 24, how
many iterations will true x%y=0 false End
be executed? out: y y=y+1
• How can it faster?
x=x/y
Legend: % is modulo operation

9
Flowchart exercises and examples
This flowchart describes the algorithm of
calculation of the remain of a division.
Complete it.
false
• Start true
• a<=b
• a<0
• b<=0 false true
• a=a-b
false true
• in: a, b
• out: error
• out: a
• End
10
Pseudocode exercises
input a • What is the output if a=10?
if a<0 then • What is the output if a=-4?
b=-1*a • What does the algorithm do?
else
b=a • What does this algorithm do?
endif
input a
output b
if a<0 then
a=-1*a
endif
output a
12
Pseudocode exercises
input a • Do the pseudocode and the flowchart
input b describe the same algorithm?
c=a
if b>0 then Start
b=b-1 in: a, b
c=c-1
else c=a
output c
endif false b>0 true

out: c b=b-1

End c=c-1
13
Pseudocode exercises
input a • How do the values of a, b and c
input b change during the process,
c=a if a=7 and b=3?
while b>0 do • What is the output in this case?
b=b-1 • How many times will the
c=c-1 condition evaluated?
enddo
• What does this algorithm do?
output c
• Convert it to flowchart.

14

You might also like