In LISP, write a recursive function 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.
I have the worst skill when it comes to creating recursion in the LISP programming language. Any help at all would be appreciated.
Description:
summation() is a recursive function which takes a number as input (user provide the input at standard input/console) and returns the summation of all positive numbers preceding it. if condition is used to break the recursion and return the summation result. LISP uses prefix expressions for evaluating so operator comes first then the operands. If n is not 1 the add the n and return value of summation() function call calling it recursively.
Solution:
Output:
Get Answers For Free
Most questions answered within 1 hours.