cwtests/cw05/sqr.fun
author Christian Urban <christian.urban@kcl.ac.uk>
Thu, 20 Jan 2022 08:58:38 +0000
changeset 868 8fb3b6d3be70
parent 856 23273e3a120f
permissions -rw-r--r--
updated to Doubles trhoughout
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
856
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     1
val Max : Int = 10;
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     3
def sqr(x: Int) : Int = x * x;
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     5
def all(n: Int) : Void = {
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     6
  if n <= Max
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
  then { print_int(sqr(n)) ; new_line(); all(n + 1) }
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     8
  else skip()
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     9
};
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    10
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    11
all(0)
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    12