solutions/cw5/sqr.fun
author Christian Urban <christian.urban@kcl.ac.uk>
Sun, 29 Oct 2023 13:05:09 +0000
changeset 948 6bb67c2dcfd3
parent 894 02ef5c3abc51
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
864
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     1
val Max : Int = 10;
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     3
def sqr(x: Int) : Int = x * x;
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     5
def all(n: Int) : Void = {
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     6
  if n <= Max
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
  then { print_int(sqr(n)) ; new_line(); all(n + 1) }
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     8
  else skip()
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     9
};
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    10
869
81ee93b87258 changed os-lib as a replacement for ammonite-ops
Christian Urban <christian.urban@kcl.ac.uk>
parents: 864
diff changeset
    11
{
81ee93b87258 changed os-lib as a replacement for ammonite-ops
Christian Urban <christian.urban@kcl.ac.uk>
parents: 864
diff changeset
    12
  print_string("Squares");
81ee93b87258 changed os-lib as a replacement for ammonite-ops
Christian Urban <christian.urban@kcl.ac.uk>
parents: 864
diff changeset
    13
  new_line();
81ee93b87258 changed os-lib as a replacement for ammonite-ops
Christian Urban <christian.urban@kcl.ac.uk>
parents: 864
diff changeset
    14
  all(0)
81ee93b87258 changed os-lib as a replacement for ammonite-ops
Christian Urban <christian.urban@kcl.ac.uk>
parents: 864
diff changeset
    15
}