comparison lab3/sumpow2.p @ 0:bfdcc3820b32

Basis
author Mike Spivey <mike@cs.ox.ac.uk>
date Thu, 05 Oct 2017 08:04:15 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bfdcc3820b32
1 (* lab3/sumpow2.p *)
2
3 proc sum(n, f);
4 var m, s;
5 begin
6 m := 0; s := 0;
7 while m < n do
8 m := m + 1;
9 s := s + f(m)
10 end;
11 return s
12 end;
13
14 proc sumpow(n, k);
15
16 proc pow(p);
17 var j, q;
18 begin
19 j := 0; q := 1;
20 while j < k do
21 j := j+1; q := q*p
22 end;
23 return q
24 end;
25
26 begin
27 return sum(n, pow)
28 end;
29
30 begin
31 print sumpow(5, 4); newline
32 end.
33
34 (*<<
35 979
36 >>*)