user379179
user379179

Reputation: 1

I need help understanding this flowchart algorithm

enter image description here

From what I understand if N≠0, you will never get the output R since N div 5 will always be supperior to 0 Is there something I'm missing ?

Upvotes: 0

Views: 157

Answers (2)

Prune
Prune

Reputation: 77827

N := N div 5 will eventually reduce N to 0; this is integer division. For instance, here are the R and N values when N starts at 28:

r   n
3   5
30  1
301 0

Work through the algorithm with pencil and paper; do you understand now?

Upvotes: 1

user9511906
user9511906

Reputation:

it's like while N is different from 0 we affect the value R*10+ (N modulo 5) to R when we get out of the loop (N equals 0) we output R

Upvotes: 0

Related Questions