### Function Programming : Fibonacci in C

Write a program to generate a Fibonacci Series. Use function.

Hints: First few numbers of series are 0, 1, 1, 2, 3, 5, 8 etc, Except first two numbers in series every other numbers are the sum of two previous numbers. For example 5 = 2 + 3 (addition of 2 & 3).

Source Code in C:
#include<stdio.h>
void fibonacci(int m, int n);
int main( )
{
int a=0, b=1;
printf("Fibonacci series is :\n\n");
fibonacci(a, b);
}
void fibonacci(int m, int n)
{
int sum=0, i;
for(i=0; i<=50; i++)
{
sum=m+n;
printf("  %d",sum);
m=n;
n=sum;
}
}

1. #include

void printFibonacci(int);

int main()
{

int k,n;
long int i=0,j=1,f;

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

printf("Fibonacci Series: ");
printf("%d %d ",0,1);
printFibonacci(n);

return 0;
}

void printFibonacci(int n){

static long int first=0,second=1,sum;

if(n>0){
sum = first + second;
first = second;
second = sum;
printf("%ld ",sum);
printFibonacci(n-1);
}

}

2. #include
main()
{
int m=0,n=1,i,sum=0;
printf("fibonacci serise :\n\n");
printf(" %d ",sum);
sum=fibonacci(m,n,i);
}

int fibonacci(int m, int n,int i)
{
int sum=0;
for(i=0;i<=14;i++)
{
sum=m+n;
printf(" \n %d \n",sum);
m=n;
n=sum;
}
return 1;
}

3. #include

int main()
{
int n,i;
int a[100]={0,1,1};
int fib, fib1=0, fib2=1;
printf("How many fibonacci numbers do you want?\n");
scanf("%d",&n);
for(i=2;i<=n;i++)
{
fib=fib1+fib2;
a[i]=fib;
fib1=fib2;
fib2=fib;
}
printf("\nFibonacci numbers up to %d terms are:\n",n);
for(i=0;i<n;i++)
{
printf("\t\n%d\n",a[i]);
}
return 0;
}

4. #include

int Fibonacci(int n)
{
if ( n == 0 )
return 0;
else if ( n == 1 )
return 1;
else
return ( Fibonacci(n-1) + Fibonacci(n-2) );
}

int main()
{
int n, i = 0, c;

printf("Enter the range of series: ");

scanf("%d",&n);

printf("\nFibonacci series\n");

for ( c = 1 ; c <= n ; c++ )
{
printf("%d,", Fibonacci(i));
i++;
}
return 0;
}

5. Id : 201430310
Name : Mehrin
Write a program to generate a fabonacci series.
#include
#include
using namespace std;
int fabonacci_series(int n,int f1, int f2,int sum =0){
while(sum>n;
f1 =0;
f2 =1;
cout<<"Fabonacci Series number: ";
printf("\n");
fabonacci_series(n,f1,f2,sum=0);
}

1. incomplete submission. try again.

6. ID no:201430310
name: Mehrin
#include
using namespace std;
int fiba(int x,int y)
{
int p=0;
cout<<" "<>a>>b;
fiba(a,b);
}

1. incomplete, not correct.

7. #include
using namespace std;
int fibonacci_number(int a, int b)
{
int c=0;
cout<<" "<>x>>y;
fibonacci_number(x,y);
return 0;
}

1. incomplete, not correct.

8. id-201210803

#include
using namespace std;
int fiba(int x,int y)
{
int p=0;
cout<<" "<1000)break;
cout<<" "<>a>>b;
fiba(a,b);
}

1. incomplete, not correct.

9. #include
using namespace std;
int fabonacci_series(int n,int a,int b,int c=0)
{
while(c<=n)
{
c=a+b;
cout<>n;
a=0;
b=1;
cout<<"fibonacci series:"<<endl;
fabonacci_series(n,a,b,c=0);
}

1. incomplete submission. not correct.

10. //test submission
#include
void fibonacci(int m, int n);
int main( )
{
int a=0, b=1;
printf("Fibonacci series is :\n\n");
fibonacci(a, b);
}
void fibonacci(int m, int n)
{
int sum=0, i;
for(i=0; i<=50; i++)
{
sum=m+n;
printf(" %d",sum);
m=n;
n=sum;
}
}

11. #include
using namespace std;
int fibonacci(int a,int b);
int main( )
{
int k=0, l=1;
cout<<"Fibonacci series is :\n\n";
fibonacci(k,l);
}
int fibonacci(int a,int b)
{
int sum=0,i;
for(i=0;i<=10;i++)
{
sum=a+b;
cout<<sum<<endl;
a=b;
b=sum;
}
}

12. Id : 201620195
https://www.dropbox.com/s/48dzmcvp2myfjcb/03.cpp?dl=0

13. ID:201520552

14. MD USUF MIA
ID 201610456
solved following by method,inheritance etc;

15. Summer 2017
ID#201610042

16. Name:Abdullah
ID:201710933

17. ID:201710494
https://www.dropbox.com/s/uik6ddkkxr5mopv/Hw2%283%29.cpp?dl=0

21. ID:-201610058

22. ID# 201610288
Section A, Summer 2017

23. #include
using namespace std;

class fib
{
public:
int a=0,b=1,i,n,sum=0;
fib()
{
cout<<"Enter length:";
cin>>n;
cout<<"Fibonacci series:"<<a<<" "<<b<<" ";

}
void cal()
{
for(i=0;i<=(n-3);i++)
{
sum=a+b;
cout<<sum<<" ";
a=b;
b=sum;
}
}
};
int main()
{
fib obj;
obj.cal();
return 0;
}