13.07.2015 Views

A practical introduction to Pascal programming language - GIARA

A practical introduction to Pascal programming language - GIARA

A practical introduction to Pascal programming language - GIARA

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Iterative constructionsInstead of using max/min functions, we could also force a <strong>to</strong> contain the lowest of both values.That is, the program can always be sure that a will have the smallest of the values, while b willhave the greatest one. In the following program we use a simple comparison <strong>to</strong> always leave ina the lowest value. Hence, by the time we reach the iteration, we know that a ≤ b.⊡Program 43: Exercise 3.5 (Version C)program c03e05;vara,b,result,aux:integer;i:integer;beginwrite(’Please type the first integer: ’);readln(a);write(’Please type the second integer: ’);readln(b);(* First we make sure that a holds the smallest value *)if (b

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!