Nth value of Function Given x and y we define a function as follow : 

f(1)=x
f(2)=y
f(i)=f(i-1) + f(i+1) for i&gt;2


Now given x and y, how to calculate f(n)

Example : If x=2 and y=3 and n=3 then answer is 1

as f(2) = f(1) + f(3), 3 = 2 + f(3), f(3) = 1.

Constraints are : x,y,n all can go upto 10^9.
Calculate the first dozen numbers.  You should find a simple result for this algorithm.
You can use this code:

#include &lt;stdio.h&gt;

int fib(int n,int x,int y){
     if (n==1) return x;
     else if (n==2) return y;
     else return fib(n-1,x,y) + fib(n-2,x,y);
}

int main()
{
   int x,y,n,z;
   printf("Give a value for x:");
   scanf("%d",&amp;x);
   printf("Give a value for y:");
   scanf("%d",&amp;y);
   printf("Give a value for n:");
   scanf("%d",&amp;n);
   z=fib(n,x,y);
   printf("The result is: %d",z);
}