Hw02 of CS61A of UCB(2021-Fall)
hw02. Higher Order Functions
Q1: Product
The
summation(n, term)function from the higher-order functions lecture adds upterm(1) + ... + term(n). Write a similar function calledproductthat returnsterm(1) * ... * term(n).
This problem is quite easy, we just need to use * instead of +. The logic is similar to summation(n, term) function in the lecture.
Remember to set ans = 1 at first, after all, 0 * any numbers is always equal to 0 🤗