solution/cw5/sqr.fun
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 28 Oct 2022 09:08:13 +0100
changeset 893 54a483a33763
parent 869 81ee93b87258
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
}