Header Ads

Fibonacci Series

Fibonacci series


How to print Fibonacci series using C program?


Fibonacci series: - The Fibonacci Sequence is the series of numbers:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34,...
The next number is found by adding up the two numbers before it.
·         The 2 is found by adding the two numbers before it (1+1)
·         Similarly, the 3 is found by adding the two numbers before it (1+2),
·         And the 5 is (2+3),
·         And so on!


Program:-


#include<stdio.h>
#include<conio.h>
main()
{
            int first,second,t,next=0,i;
            printf("Enter the first number of Fibonacci series: \n");
            scanf("%d",&first);
                 
            printf("Enter the second number of Fibonacci series :\n");
            scanf("%d",&second);  
              
            printf("Enter the number of elements u want to print in your Fibonacci series after first & second term : \n");
            scanf("%d",&t);
           
            printf("series : \n");
            printf("%d %d ",first,second);
            next=first+second;
            for(i=1;i<=t;i++)
            {
                        next=first+second;
                        printf("%d ",next);
                        first=second;
                        second=next;
            }
            getch();
}

Output:-


Enter the first number of Fibonacci series:
5
Enter the second number of Fibonacci series:
6
Enter the number of elements u want to print in your Fibonacci series after first & second term:
7
Series:

5  6  11  17  28  45  73  118  191

No comments