UncleCoder.com

UncleCoder.com

Free programming examples and instructions

Posted on 05 Sep 2017 Category: C Views: 248

Edited on 21 Sep 2017

How to display the Fibonacci sequence up to the limit n???

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

```
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,f1=-1,f2=1,f3=0;
printf(“Enter the limit :”);
scanf(“%d”,&n); // getting input from the user
printf(“Fibonacci series upto the limit %d are :\n”,n);
for(i=1;i<=n;i++)
{
f3=f1+f2; //f3 is the next number and next number in the sequence is the sum of previous two terms ie, f1 and f2
printf(“%d\t”,f3);
f1=f2; //first=second
f2=f3; //second=next
}
getch();
}
```

In the first iteration f3=0(-1+1)

f1=1

f2=0

In the second iteration f3=1(1+0)

f1=1

f2=1

This iteration process continuous until the condition become false.

**output**

##### Add two numbers C

##### C program to find factorial of a number

##### C program to generate Multiplication table using for loop

##### C program to study the Conditional Statements

##### C program to study 'Bubble Sort'

##### C program to find largest among two numbers without else.

##### C program to Sort a given set of strings

Contact : [email protected]

User IP : 54.80.198.173