progs/fact.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Wed, 06 Mar 2024 18:20:25 +0000
changeset 484 c4561fc667b7
parent 449 d67c5f7177a6
permissions -rw-r--r--
test
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 Fact {
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 fact(n: Int): Int = 
d67c5f7177a6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
  if (n == 0) 1 else n * fact(n - 1)
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
}