I want to create a sequence as follows: 1,2,4,7,13,24. This works by Finding the next term by adding the values of the 3 terms before it in the sequence. I am really struggling to get anywhere writing this code recursively, no idea where to begin.
Here is the iterative code:
CODE
#include <stdio.h>
#include <stdlib.h>
#define iterations 6
//Sequence List Iteration Function 1, 2, 4, 7, 13, 24
void Sequence1()
{
int i;
int number[3]={1,2,4};
int A, B;
printf("%d %d ", number[0], number[1]);
for (A = 0; A < iterations-2; A++)
{
printf("%d ",number[2]);
int number2 = number[2] + number[1] + number[0];
for (B = 0; B < 2; B++) number[B] = number[B + 1];
number[2]=number2;
}
printf("\n");
}
int main()
{
//Print out iteration greater than
Sequence1();
return 0;
}
This post has been edited by kkgaming: 19 Mar, 2007 - 02:06 PM