C
c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Fibonacci Series using Recursion
// Positive and negative numbers
#include <stdio.h>
int Pfib(int n) // The positive Fibonacci Sequence
{
if (n <= 1) return n;
return Pfib(n-1) + Pfib(n-2);
}
int Nfib(int n) // The Negative Fibonacci Sequence
{
if (n >= -1) return n;
return Nfib(n+1) + Nfib(n+2);
}
int main()
{
int n;
printf( "Enter a number :");
scanf ("%d", &n);
printf(" %d\n", n);
if (n>0) {
puts("The positive Fibonacci Sequence");
for(int i=0; i<=n; i++) printf("%d ", Pfib(i) );
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run