Write a recursive function to obtains the first 25 numbers of a Fibonacci sequence.

Q. Write a recursive function to obtains the first 25 numbers of a Fibonacci sequence

Summary:-
In Fibonacci sequence the sum of two successive terms gives the third term. Following are the first few terms of Fibonacci sequence:
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, . . .

1. Without Recursion


#include <stdio.h>
int main()
{
int a=0,b=1,temp;
int x =0;
while(x<10)
{
printf("%d ",b);
temp=a+b;
a=b;
b=temp;
x++;
}
return 0;
}

2. By Recursion


#include <stdio.h>
int a=0,b=1,temp;
int x =0;
int main()
      {

if(x<10)
{
printf("%d ",b);
temp=a+b;
a=b;
b=temp;
x++;
main();
}
return 0;
       }

Comments

Popular posts from this blog

Write a function that receives 5 integers and returns the sum , average and standard deviation of these numbers. Call this function from main( ) and print the result in main( ).

Patch Up Two Matrices

A 5-digit positive integer is entered through the keyboard ,write a recursive and non-recursive function sum of the 5-digit number.