diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lab3/sumpow.p	Thu Oct 05 08:04:15 2017 +0100
@@ -0,0 +1,31 @@
+(* lab3/sumpow.p *)
+
+proc sumpow(n, k);
+  var m, s;
+
+  proc pow(p);
+    var j, q;
+  begin
+    j := 0; q := 1;
+    while j < k do 
+      j := j+1; q := q*p
+    end;
+    return q
+  end;
+
+begin
+  m := 0; s := 0;
+  while m < n do 
+    m := m + 1; 
+    s := s + pow(m)
+  end;
+  return s
+end;
+
+begin
+  print sumpow(5, 4); newline
+end.
+
+(*<<
+ 979
+>>*)