Question: A geometric sequence is a sequence in which each term is found by multiplying the preceding term by the same value. Its general term is

A geometric sequence is a sequence in which each term is found by multiplying the preceding term by the same value. Its general term is
an=a1*rn-1
Write a recursive function to generate first n terms of a geometric sequence. This function should take a1,r,and n as inputs, and output first n terms in an array.
If any of the inputs are non-numeric, a1=0,r=0,or n is not an integer greater than or equal to 1,your function should output an empty array, i.e.[].
You are required to use recursion ONLY to solve this problem. Using loops will cost you 13of the points even if you solve it correctly.
Hints: don't want to do typecasting here either which might change the original value of n.One possible solution is to check if the remainder after division of n by 1is 0.
Recall what we did in Recursive Fibonacci. Your function should always produce an output with any n including n=1when no recursion is needed. Use if-else(if)condtional to include all the edge cases.

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 Programming Questions!