Display Fibonacci Sequence

C Program to Display Fibonacci Sequence

To Write a program that would to Display Fibonacci Sequence. The C program to display Fibonacci Sequence using loops is given in below simple example.

Unlike for and while loops, which test the loop condition at the top of the loop, the do…while loop in C programming checks its condition at the bottom of the loop.

A do…while loop is similar to a while loop, except the fact that it is guaranteed to execute at least one time.

To understand this example, you should have the knowledge of following C programming topics:

Fibonacci Sequence Flow Diagram

 

 

Save program in a file, Compile program, debug errors, Execute or Run program with necessary inputs. Verify the outputs obtained.

Example:  C Program to Display Fibonacci Sequence

/*Program to print Fibonacci series*/
void main()
{
int i=1,n,f,f1,f2;
printf("enter the range");
scanf("%d",&n);
f=0;
f1=0;
f2=1;
   do
     {
      i++;
      printf("%d\n",f);
      f=f1+f2;
     f2=f1;
     f1=f;
    }
while(i<=n);
}

The Fibonacci sequence is a series where the next term is the sum of previous two terms. The first two terms of the Fibonacci sequence is 0 followed by 1

Output

Enter the range 9
0 1 1 2 3 5 8 13 21

Let me know if you find any difficulty in understanding this C Program example and I would be glad to explain it further.