comparison lab3/sumpow.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/sumpow.p *)
2
3 proc sumpow(n, k);
4 var m, s;
5
6 proc pow(p);
7 var j, q;
8 begin
9 j := 0; q := 1;
10 while j < k do
11 j := j+1; q := q*p
12 end;
13 return q
14 end;
15
16 begin
17 m := 0; s := 0;
18 while m < n do
19 m := m + 1;
20 s := s + pow(m)
21 end;
22 return s
23 end;
24
25 begin
26 print sumpow(5, 4); newline
27 end.
28
29 (*<<
30 979
31 >>*)