Consider the following sequence:

\(\Big\{\begin{array}{c} U_0=U_1=1 \\ U_n=2 \times U_{n-1}+3 \times U_{n-2} \end{array}\)

  1. Write the function int Seq (int n) that returns the value of the element.
  2. Write a main function that print the first 20 elements of the sequence.

Difficulty level
This exercise is mostly suitable for students
#include<stdio.h>

int Seq(int n)
{
	int i;
	int u0=1, u1 = 1, u2=1;
	for(i=2; i<=n;i++)
	{
		u2=2*u1+3*u0;
		u0=u1;
		u1=u2;
	}
	return u2;
}

void main()
{
	int i;
	for(i=0;i<20;i++)
		printf("U%d=%d\n",i,Seq(i));
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Kruskal Algorithm - Minimal Spanning Tree