# C Program to Find Fibonacci Series

Here, we will write the C program to find the Fibonacci series, and also we will write another C program to find the nth term of the Fibonacci series.

In the Fibonacci series, the next element will be the sum of the previous two elements. The Fibonacci sequence is a series of numbers where a number is found by adding up the two numbers before it. Starting with 0 and 1, the sequence goes 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and so forth. Written as a rule, the expression is Xn= Xn-1+ Xn-2

By definition, the first two numbers in the Fibonacci sequence are either 1 and 1, or 0 and 1, depending on the chosen starting point of the sequence, and each subsequent number is the sum of the previous two.

C Program to Find Fibonacci Series

`````` #include<stdio.h>
int main()
{
int a=0, b=1, num, c;

printf("Enter number of terms: ");
scanf("%d",&num);

for(int i=0; i<num; i++)
{
printf("%d\t",a);
c = a + b; //next term
a = b;
b = c;
}

return 0;
}``````

Output:-

Enter number of terms: 7
0 1 1 2 3 5 8

Enter number of terms: 10
0 1 1 2 3 5 8 13 21 34

## Find Fibonacci series in a range

`````` #include<stdio.h>
int main()
{
int a=0, b=1, range, c;

printf("Enter the range of Fibonacci series: ");
scanf("%d",&range);

while( a <= range )
{
printf("%d\t",a);
c = a + b;
a = b;
b = c;
}

return 0;
}``````

Output:-

Enter the range of Fibonacci series: 20
0 1 1 2 3 5 8 13

Enter the range of Fibonacci series: 200
0 1 1 2 3 5 8 13 21 34 55 89 144

## C program to Find Nth Fibonacci term

Sometimes, we need to find the nth Fibonacci term of the Fibonacci series.

`````` #include<stdio.h>
int main()
{
int a=0, b=1, num, c;

printf("Enter the term (>2): ");
scanf("%d",&num);

for(int i=1; i<num; i++)
{
c = a + b;
a = b;
b = c;
}

printf("The Fibonacci term is: %d\t",a);

return 0;
}``````

Output:-

Enter the term (>2): 7
The Fibonacci term is: 8

Enter the term (>2): 10
The Fibonacci term is: 34

The first and second term of the Fibonacci series is 0 and 1 respectively. So, we should enter the term greater than 2.

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

### 2 thoughts on “C Program to Find Fibonacci Series”

1. Seems to be an error with your nth term Fibonacci code, running it myself, when I input 7 as the term, I do not get 8, but rather, 21.