define fibonacci code example
Example 1: fibonacci
def fibonacci(n):
if n == 1:
return 0
elif n == 2:
return 1
else:
return fibonacci(n - 1) + fibonacci(n - 2)
def fibonacci2(n):
if n == 0: return 0
n1 = 1
n2 = 1
for i in range(1, n - 2):
n1 += n2
n2 = n1 - n2
return n1
print(fibonacci(13))
Example 2: fibonacii
void fibonacci(int num);
void main()
{
int num = 0;
clrscr();
printf("Enter number of terms\t");
scanf("%d", &num);
fibonacci(num);
getch();
}
void fibonacci(int num)
{
int a, b, c, i = 3;
a = 0;
b = 1;
if(num == 1)
printf("%d",a);
if(num >= 2)
printf("%d\t%d",a,b);
while(i <= num)
{
c = a+b;
printf("\t%d", c);
a = b;
b = c;
i++;
}
}