Question

In LISP, write a recursive function that takes an integer n and returns the summation of...

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.

Homework Answers

Answer #1

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:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
this assignment is about solving problems using recursion. For each question, write a recursive function that...
this assignment is about solving problems using recursion. For each question, write a recursive function that solves the problem asked in that question. Your solutions don't have to be efficient, but they do have to use recursion in a non-trivial way. Put all your code in a file called a9.py. Write a recursive function is_palindrome(s) that returns True or False depending on whether s is a palindrome. This is equivalent to returning s == s[::-1]. Write a recursive function find_min(a)...
write a recursive racket function "sum-alternate" that takes a positive integer x as a parameter. The...
write a recursive racket function "sum-alternate" that takes a positive integer x as a parameter. The function should return the sum of all the integers x, x-2, x-4, x-6, etc. as long as the numbers are positive. For example, [sum-alternate 5] should evaluate to 5 + 3 + 1, and [sum-alternate 6] should evaluate to 6+4+2.
C++ question: Write a recursive function that takes a non-negative integer as an argument and returns...
C++ question: Write a recursive function that takes a non-negative integer as an argument and returns an integer with the same digits of the argument in reverse order (i.e. in order from right to left). All trailing zeros in the argument number are omitted. For example, if the argument is 76038, it would return 83067 and if the argument is 45600 it returns 654.
For C++: a) Write a function is_prime that takes a positive integer X and returns 1...
For C++: a) Write a function is_prime that takes a positive integer X and returns 1 if X is a prime number, or 1 if X is not a prime number. b) write a program that takes a positive integer N and prints all prime numbers from 2 to N by calling your function is_prime from part a.
C Programming: Write a function that takes in an array of integers and an integer containing...
C Programming: Write a function that takes in an array of integers and an integer containing the count of elements, then have it returns the sum of all the even values inside the array.
Write the recursive version of the function decimal which takes in n, a number, and returns...
Write the recursive version of the function decimal which takes in n, a number, and returns a list representing the decimal representation of the number. def decimal(n): """Return a list representing the decimal representation of a number. >>> decimal(55055) [5, 5, 0, 5, 5] >>> decimal(-136) ['-', 1, 3, 6] """
In C++ Using recursion write a program that takes a positive integer number and returns whether...
In C++ Using recursion write a program that takes a positive integer number and returns whether there is 6. For example, if the input number is 7068, the function returns true
Write an OCaml function named is_square that takes as input an integer, say n, (which may...
Write an OCaml function named is_square that takes as input an integer, say n, (which may be positive or negative) and returns true if that number is square. That is, it returns true if there exists an an integer, say m, if m * m = n. Next, write a function named count_squares that calls count from above to determine the number of squares in a list of integers. For example, count_squares [2;3;5] = 0 count_squares [1;2;3;4;5;6;7;8;9] = 3
In C programming language write a function that takes an integer n as input and prints...
In C programming language write a function that takes an integer n as input and prints the following pattern on the screen: 1 (n times) 2 (n-1 times) .n (1 time) For example, if n was 5, the function should print 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5
Please write function in Racket language. Write a recursive Racket function "sum-diff" that takes two lists...
Please write function in Racket language. Write a recursive Racket function "sum-diff" that takes two lists of integers that are the same length and evaluates to an integer. The resulting integer should be the sum of the absolute value of the differences between each pair of integers with the same index in the two lists. For example (sum-diff '(-1+2+3)'(123)) should evaluate to 12 because the absolute value of the differences between (-1 and 1), (-2 and 2) and (-3 and...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT