Write a program to find sum of Fibonacci series using function.
#include<conio.h>
#include<stdio.h>
int sumfab(int num)
{
int a=1,b=1,sum=2,i,c;
printf("%d,%d,",a,b);
for(i=3;i<=num;i++)
{
c=a+b;
sum=sum+c;
a=b;
b=c;
printf("%d,",c);
}
return sum;
}
void main()
{
int n,sum;
printf("enter a number \n");
scanf("%d",&n);
sum=sumfab(n);
printf("the sum is %d",sum);
getch();
}
No comments:
Post a Comment