Question: C. Instructions Code the following functions in a single lisp file named homework.lisp 1) In a comment, describe what the following code do when it

C. Instructions

Code the following functions in a single lisp file named homework.lisp

1) In a comment, describe what the following code do when it is executed; also, provide an equivalent method/function foo in Java or C/C++

2) In a comment, describe what the following code do when it is executed; also, provide an equivalent method/function myPrint in Java or C/C++

3) Write an iterative function that calculate the factorial of a positive integer and return the result. The function should be equivalent to this Java code.

public static double factorial1 (double n) { double sum = 1;

 for (double i=0; i < n; i++) sum = sum * (1 + i); 

return sum; }

4) Write a recursive function that calculate the factorial of a positive integer and return the result. The function should be equivalent to this Java code.

public static double factorial2 (double n) { if (n<=1)

 return 1; else 

return n * factorial2 (n-1);

}

5) Write a function, named amount, that takes a list and returns the number of times thesymbol 'a' occurs in it. Note: do not count a's that might occur in a sublist within the list.

6) Write a recursive function that returns the Fibonacci number where the Fibonacci sequence is defined as

fib(0)=0, fib(1)=1 and fib(n)=fib(n-1)+fib(n-2) for n > 1. 
 examples: n = 0 1 2 3 4 5 6 7 8 9 ... fib(n) = 0 1 1 2 3 5 8 13 21 34 ... 

7) Write a function, named small, that takes 2 numbers and returns the smaller of the two.

8) Write a function, named sum, that takes an integer n and returns the summation of n and all

positive integers preceding it; e.g., passing 5 will return 15, which is 1+2+3+4+5.

9) In a comment, describe what the following code do when it is executed; explain each line and whether the result is a symbol or a list

10) Define a function test that runs all of the above functions (items 4, 5, 6, 7, 8) as follows.Replace PUT YOUR NAME HERE for your name.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!