thank you very much guys.
I forgot to mention that I am practicing writing algorithms by induction and that was one question the instructor gave us .
After some tries I relied that the best way to write it recursively is to save the returned value and add the next returned to it by using a variable defined out side the function, but the problem was How could I make the first call for the function returns the value in that variable and make other calls return the square?
I got some help from a friend and end up with this function
int i,z,f;
bool m=false;
int sqr(int n)
{
int i,j=0;
if(n>1)
{
if(!m)
{
z=n;
m=true;
}
i=sqr(n-1)+n+n-1;
f=f+i;
if(n==z)
return f;
else
return i;
}
else
return f=1;
}
thank you very much, your posts were very helpful