Given a number n, it is your job to multiply the n by all the numbers that are below it stopping at 1.
So if n = 3 then the output should be 3 * 2 * 1 = 6
fun fact(n: Int): Int {
var fact = 1
var check = n
while(check > 0) {
fact *= check
check--
}
return fact
}
// You can test using JUnit or KotlinTest. JUnit is shown below
// TODO: replace this example test with your own, this is just here to demonstrate usage.
// TODO: replace with whatever your package is called
import kotlin.test.assertEquals
import org.junit.Test
class FactTest {
@Test
fun testFact() {
assertEquals(2, fact(2))
assertEquals(720, fact(6))
assertEquals(3628800, fact(10))
}
}