Subscribe for more such posts..

Dear Reader...
I hope u are like my posts. If so then please don't forget to like , share and follow my blog for more such posts ,also feel free to write suggestions in the comment box given over here.

Thank you...

Search This Blog

C program to find the sum of the fibonacci series using function.


 

#include <stdio.h>
long double func (int r)
{
	long double first = -1 , second = 1 , sum = 0 , third;
	
	for (int i = 0 ; i < r ; i ++)
	{
		third = first + second ;
		sum = sum + third ;
		first = second;
		second = third ;
	}
	
	return sum ;
	
}


int main()
{
	int range ;
	printf("Enter the range: ");
	scanf("%d" , &range);
	

	printf("Sum of Fibonacci series for given range is: %.0Lf\n" , func(range));
	
	return 0 ;
	
}

No comments:

Post a Comment