Need help with finding N.


Joined
Nov 21, 2022
Messages
1
Reaction score
0
Hello,
I need help for the following problem:
Compose functions that find the Nth member of a series that is formed by the following rule:
Ai = 3*Ai-3 +4* Ai-2 - 7 * Ai-1
A1 = 2; A2 = 4; A3 = 6;
- Compose an iterative version of this function
- Form a recursive version of this function

Preferably C#. I would be very grateful for any help provided.
 
Ad

Advertisements

Joined
Sep 21, 2022
Messages
19
Reaction score
3
Hello,
I need help for the following problem:
Compose functions that find the Nth member of a series that is formed by the following rule:
Ai = 3*Ai-3 +4* Ai-2 - 7 * Ai-1
A1 = 2; A2 = 4; A3 = 6;
- Compose an iterative version of this function
- Form a recursive version of this function

Preferably C#. I would be very grateful for any help provided.

The Fibonacci sequence is similar to this problem.

A beautiful demonstration of recursion is called Towers of Hanoi.

rosettacode.org is a wiki that contains simple programs like that, written in many different languages, including c#.

Search "recursion" on that web site for other examples.
Code:
recursion pseudocode:

function f(n)
if n==1 then
  r=2
elseif n==2 then
  r=4
elseif n==3 then
  r=6
else
  r=3*f(n-3) + 4*f(n-2) - 7*f(n-1)
end if
return r

iteration pseudocode:

function f(n)
a=2
b=4
c=6
for i=4 to n
  d=3*a + 4*b - 7*c
  a=b
  b=c
  c=d
end for
return c
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top