1. recursion!!!

below i am trying to print fibonacci series using recursion.

Code:
```#include<stdio.h>
#include<conio.h>

int fib(int);

int main()
{
fib(5);
getch();
}

int fib(int n)
{   int  a;

if(n==0||n==1)
return 1;

else
a=fib(n)+fib(n-1);
printf("%d\t",a);

return a;
}```
i am getting output as: 2 3 2 5 2 3 8
which is wrong

i am not able to figure out how recursion works in the above program???

thanks
samir

2. Inside fib, you have fib(n) calling the function fib(n). Which will in turn call fib(n), which will call fib(n), which will call fib(n). Then this function will call fib(n), which will proceed to call fib(n). At which point fib(n) will be called.

Perhaps you meant
Code:
`a = fib(n - 1) + fib(n - 2);`

3. Here you have the code of a Fibonacci progresion.

Code:
```//---------------------------------------------------------------------------

#pragma hdrstop

//---------------------------------------------------------------------------
#include <stdio.h>
#pragma argsused
int main(int argc, char* argv[])
{
int n, a, b, c;

printf("Introduzca el numero de terminos: ");
scanf("%i", &n);

do {
a=1;
b=1;
printf("%i, ", a);
c++ ;
}while (c<2);

do{
a=(a+b);
b=a;
printf("%i, ", a);
c++;
}while (c<n);

getchar();
return 0;

return 0;
}
//---------------------------------------------------------------------------```

4. >Here you have the code of a Fibonacci progresion.
Poorly written, non-portable, broken code with no formatting that fails to recognize that everyone here communicates in English. I fail to see how your post is anything more than an attempt to boost your post count without having to think.