hi, im trying to write a program to solve the equation
A(n) = 2A(n-1)-3A(n-2) for n>1.
A(0) = 1 and A(1) = 2.
I've already wrote a recursive program to solve it but am trying to get an iterative version to work. The code I am using for the iterative version is below:
I am not entirely sure where I am going wrong, but this code leads to an infinite loop of nothing, and I cannot come up with a way of iterating a and b to get the desired result. I have also tried while loops and nested for loops without much luck. If anyone can point me in the right direction, I'd be grateful.Code:int A(int n) { int a, b; a = n-1; b = n-2; if(a==0||b==0) a=1; if(a==1||b==1) a=2; while(a>0&&b>1) { n = 2*a-3*b; } return n; }