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