Question: Objective: 1. Understand the recurrence relation of sequences 2. In C++, know how to use the recurrence relation to calculate the n-th term of thesequence,

Objective:

1.

Understand the recurrence relation of sequences

2.

In C++, know how to use the recurrence relation to calculate the n-th term of thesequence, where n is input by users. Given the following recurrence relations of two sequences, write a function for each sequence. The function should return the n-th term of the sequence, where n is input by users. Print out the value in the console.

1. an = 2 * an-1 + 3 * an-1; a0 = -2, a1 = 3.

2. an = 2*an - n; a1 = 2.

Hint:

1. A single for loop in the function will suffice.

2. Function template is

int

YourFuntionName(int n){

1. Initialize the starting values(i.e. a0 or/and a1)

2. If n = 0 or 1, return a0 or a1

3. If n != 0 or 1, Write a for loop, return an

}

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!