105k views
0 votes
g Write a recursive function, seq_of_mult_3, which models the recursive function that generates the sequence = {2, 6, 18, 54, 162 ...}. The function should take in the one input parameter that represents the nth value to calculate.

1 Answer

2 votes

Step-by-step explanation:

In computer programming, a recursive function is one that calls itself and breaks when a certain condition is met, otherwise it keeps on running.

IN the given scenario, the recursive formula would be;

an = 3an - 1

Here n is nth term, an is the An value of function for nth term and An-1 is for one previous value.

global

int nth_val

int curr_val

int output = 2

def recursive(nth_val):

{

While ( curr_val < nth_val)

Print (Output)

Output = Output x 3;

curr_val++;

recursive(nth_val):

break

}

Int main void

{

Int number;

number = input("Please input the nth number of series: ")

nth_val = number

recursive(nth_value):

}

User Zaky German
by
3.4k points