# Sum of Fibonacci Series in C

Write a program to find the sum of the Fibonacci series in C language. Previously, we have written a C program for 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.

Sum of Fibonacci series in a range

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

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

printf("The fibonacci series is: \t");
while( a <= range )
{
printf("%d\t",a);
sum += a;
c = a + b;
a = b;
b = c;
}

printf("\nTheir sum is = %d", sum);

return 0;
}``````

Output for different test-cases:-

Enter the range of Fibonacci series: 20
The fibonacci series is: 0 1 1 2 3 5 8 13
Their sum is = 33

Enter the range of Fibonacci series: 50
The Fibonacci series is: 0 1 1 2 3 5 8 13 21 34
Their sum is = 88

## Sum of first N terms of Fibonacci series in C

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

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

for(int i=0; i<num; i++)
{
sum += a;
c = a + b; //next element
a = b;
b = c;
}

printf("Sum = %d", sum);

return 0;
}``````

Output for different test-cases:-

Enter number of terms: 9
Sum = 54