Search This Blog


Friday, 12 April 2019

Program to Create Fibonacci series in Language C

Program to Create Fibonacci series in Language C

WELCOME BACK TO CODEJUNCTION.IN , good to see you again on our blog , Make sure to check out our other blogs too.

 In this program the user needs to enter the number then the program will produce Fibonacci series to that number.

 What is Fibonacci Series in C Language ?
Fibonacci series in C programming: C program for Fibonacci series using a loop and recursion. Using the code below you can print as many terms of the series as required. Numbers of this sequence are known as Fibonacci numbers. The first few numbers of the series are 0, 1, 1, 2, 3, 5, 8, ...,. Except for the first two terms of the sequence, every other term is the sum of the previous two terms, for example, 8 = 3 + 5 (addition of 3 and 5).


CODE


int main()
{
    int count,first= 0, second= 1, next, i;

   
    printf("Enter the number of terms:\n");
    scanf("%d",&count);                                            //takes value from you

    printf("First %d terms of Fibonacci:\n",count);
    for ( i = 0 ; i < count ; i++ )
    {
       if ( i <= 1 )
          next= i;
       else
       {
          next= first+second;
          first= second;
          second= next;
       }
       printf("%d \n",next);
    }

    return 0;
}

OUTPUT







No comments:

Post a Comment