Skip to content

Instantly share code, notes, and snippets.

@jagdish4501
Created May 10, 2021 08:58
Show Gist options
  • Save jagdish4501/cd853ea501aa3be0af55e31947f38492 to your computer and use it in GitHub Desktop.
Save jagdish4501/cd853ea501aa3be0af55e31947f38492 to your computer and use it in GitHub Desktop.
Let us c Q.Write a recursive function to obtain the first 25 numbers of a Fibonacci sequence. In a Fibonacci sequence the sum of two successive terms gives the third term. Following are the first few terms of the Fibonacci sequence: 1 1 2 3 5 8 13 21 34 55 89 ........
/* fibonacci series*/
#include <stdio.h>
int fibonacci(int i);
int main()
{
int temp;
printf(" fibonacci seriese s=");
for (int i = 1; i <= 25; i++)
{
temp = fibonacci(i);
printf("%d ", temp);
}
printf(" ..........up to n term");
}
int fibonacci(int i)
{
if (i == 0 || i == 1)
{
if (i == 0)
{
return 0;
}
else
return 1;
}
else
return fibonacci(i - 1) + fibonacci(i - 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment