Saturday 14 March 2015

Program to find the sum of fibonacci series Using C

# include <stdio.h>
# include <conio.h>
void main()
{
int a = -1, b = 1, c = 0, i, n, sum = 0 ;
clrscr() ;
printf("Enter the limit : ") ;
scanf("%d", &n) ;
printf("\nThe fibonacci series is : \n\n") ;
for(i = 1 ; i <= n ; i++)
{
c = a + b ;
printf("%d \t", c) ;
sum = sum + c ;
a = b ;
b = c ;
}
printf("\n\nThe sum of the fibonacci series is : %d", sum) ;
getch() ;
}


RUN 1 :
~~~~~~~
Enter the limit : 5
The fibonacci series is :
0 1 1 2 3
The sum of the fibonacci series is : 7

No comments:

Post a Comment