Another open university assignment. Again Pascal.
Write a program max that reads integer values from standard input and returns the max value.
0 terminates the input.
This is my solution:
And this is the university’s solution:
So what’s the difference?
A bit nicer structure. But basically the same program.
Why do we need an additional readln (Number)?
This is an optimization. E.g. in case I enter the number 8 first and then the number 0, the while-loop will not be executed. Otherwise (without readln (Number)) we enter the while-loop, perform an unnecessary check (if Number > MaxNumber; if 8 > 8), then read the 0 and exit the while-loop. My solution actually performs this unnecessary step as well.
Understood.