Monday, December 15, 2014

Fibonacci series



According in mathematics, the Fibonacci number or sequence are the numbers in the following integer sequence:

1 ,1, 2, 3, 5, 8, 13, 21…….
Or (in modern usage):

0, 1, 1, 2, 3, 5, 8, 13, 21, 34…………

So  definition, the first two numbers in the Fibonacci sequence are 1 and 1, or 0 and 1, depending on the chosen starting point, and each subsequent number is the sum of the previous two numbers.
In mathematical , the sequence Fn of Fibonacci numbers is defined by the recurrence relation:  






With values


 
 or





The major property used in Fibonacci Series Algorithm and Flowchart. The series starts with  0 or 1 and the sum of each subsequent number is the sum of previous two numbers as follows:






First       Number =0
Second    Number=1
Third      Number=First+Second=0+1=1
Fourth     Number=Second+Third=1+1=2
Fifth       Number=Third+Fourth=2+1=3
Sixth       Number= Fourth+Fifth=3+2=5
Seventh    Number=Fifth+Sixth=3+5=8
Eighth      Number= Sixth + Seventh = 5+8 = 13 … ……….infinitive 



Algorithm:

  • Start
  • Declare variables n=1, j,sum ,m,fvalue=0,svalue=1;
  • Enter the term for fibonicy: to be printed
  • Use loop for the following steps such as: while(n<=m)
  • Printf  the first value;
                    sum=fvalue+svalue;
                   fvalue=svalue;
                   svalue=sum;
                   increase value of n each time by 1
  • End
 

This problem  is related about recursion. Firstly user input a integer. Then result show a Fibonacci series.Last number of series must be equal the user’s input value. Now write a program how to show Fibonacci series from user input.
Sample input: 
Enter number of terms: 5
Output: 1 1 2 3 5

Solve Code:


#include <stdio.h>
int main(){
int n,j,sum,m;
int fvalue=0;
int svalue=1;
n=1;
printf("Enter the term for fibonicy:");
scanf("%d",&m);
while(n<=m){
    printf(" %d ",fvalue);
    sum=fvalue+svalue;
    fvalue=svalue;
    svalue=sum;
    n++;

}
return 0;
}

No comments:

Post a Comment