program to get series (Fibonacci)0,1,1,2,3,5,8....15th term.

//program to get series 0,1,1,2,3,5,8....15th term.
void main()
    int i=0,j=1,n,k;
      printf("enter  nth  number for 'n'\n");
          printf( "%d\n",k);
logics in mind:
->take two initial numbers as 'i' and 'j' for first two values '0' and '1'. If you want then you can input these numbers and display them.
->since we need to display 15th terms so we input 15 or 16 for variable 'n'. We can also fix it inside loop.
->Fibonacci series is that where we get terms by adding two previous terms.
->We have displayed first two terms (0 and 1). now we need to display only 13th terms.
->We display that using loop.
->inside loop, we get next term by adding fist two terms (look above).
     ->we display that.
     ->now we assign value of 'j' to 'i' and 'k' to 'j'. it works and goes on working for next cycle/iteration

No comments:

Post a Comment