progs/factT.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Mon, 26 Dec 2022 16:49:53 +0000
changeset 458 d9f8245d0861
parent 449 d67c5f7177a6
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
449
d67c5f7177a6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     1
object FactT {
d67c5f7177a6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
d67c5f7177a6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     3
def factT(n: Int, acc: Int): Int =
d67c5f7177a6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
  if (n == 0) acc else factT(n - 1, n * acc)
d67c5f7177a6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     5
d67c5f7177a6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     6
}