equal
deleted
inserted
replaced
11 |
11 |
12 \begin{enumerate} |
12 \begin{enumerate} |
13 \item Write a program in the WHILE-language that calculates |
13 \item Write a program in the WHILE-language that calculates |
14 the factorial function. |
14 the factorial function. |
15 |
15 |
16 \begin{lstlisting} |
16 %\begin{lstlisting} |
17 write "factorial: "; |
17 %write "factorial: "; |
18 read n; |
18 %read n; |
19 minus1 := 1; |
19 %minus1 := 1; |
20 while n > 0 do { |
20 %while n > 0 do { |
21 minus1 := minus1 * n; |
21 %minus1 := minus1 * n; |
22 n := n - 1 |
22 %n := n - 1 |
23 }; |
23 %}; |
24 write "Result: "; |
24 %write "Result: "; |
25 write minus1 ; |
25 %write minus1 ; |
26 write "\n" |
26 %write "\n" |
27 \end{lstlisting} |
27 %\end{lstlisting} |
28 |
28 |
29 \item What optimisations could a compiler perform when |
29 \item What optimisations could a compiler perform when |
30 compiling a WHILE-program? |
30 compiling a WHILE-program? |
31 |
31 |
32 \solution{ |
32 \solution{ |