#include <stdio.h>
void non_recursive(int v1, int v2, int n)
{
printf("%d %d ", v1, v2);
for(int i = 0; i < n-2; ++i)
{
int tmp = 2 * (v1 + v2);
v1 = v2;
v2 = tmp;
printf("%d ", tmp);
}
}
void recursive(int v1, int v2, int n)
{
printf("%d ", v1);
if(--n > 0)
{
recursive(v2, 2 * (v1 + v2), n);
}
}
int main()
{
const int n = 6;
non_recursive(1, 2, n);
printf("\n");
recursive(1, 2, n);
printf("\n");
return 0;
}
Comments
Leave a comment