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( ).

Write a function that receives marks received by a student in 3 subject and return the average and percentage of these marks. Call this function from main( ) and print the results in main( ).

A positive integer is entered through the keyboard , write a program to obtain the prime factors of the number . Modify the function suitably to obtain the prime factors recursively .