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;
      }
}

28 comments:

  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);
    }

    }

    ReplyDelete
  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;
    }

    ReplyDelete
  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;
    }

    ReplyDelete
  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;
    }

    ReplyDelete
  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);
    }

    ReplyDelete
    Replies
    1. incomplete submission. try again.

      Delete
  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);
    }

    ReplyDelete
    Replies
    1. incomplete, not correct.

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

    ReplyDelete
    Replies
    1. incomplete, not correct.

      Delete
  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);
    }

    ReplyDelete
    Replies
    1. incomplete, not correct.

      Delete
  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);
    }

    ReplyDelete
    Replies
    1. incomplete submission. not correct.

      Delete
  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;
    }
    }

    ReplyDelete
  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;
    }
    }

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

    ReplyDelete
  13. ID:201520552
    1)https://drive.google.com/open?id=0B5pG0kIjzgEKUHc0aXAwZGZrWFU
    2)https://drive.google.com/open?id=0B5pG0kIjzgEKRXh4WXhQNzZJbU0

    ReplyDelete
  14. MD USUF MIA
    ID 201610456
    solved following by method,inheritance etc;
    link below:

    https://drive.google.com/open?id=0B_PIGnOMR0K2Sm91aWN1dzFGZm8

    ReplyDelete
  15. Summer 2017
    ID#201610042

    https://drive.google.com/file/d/0B99eePh0LV8gdndmTHhkcy04ZWs/view?usp=drivesdk

    ReplyDelete
  16. Name:Abdullah
    ID:201710933
    https://drive.google.com/open?id=0B0bbxKUPFizZNmFBd2M1QU9PUWs

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

    ReplyDelete
  18. https://drive.google.com/open?id=0B3bVD5Ppt_STQnQzTERSM1VCdkU

    ReplyDelete
  19. https://drive.google.com/open?id=0Byxq3aat_mNSbVljRUJHQ2xlLW8

    ReplyDelete
  20. https://drive.google.com/open?id=0B5eevQy6QwSObExWQzBELVhTR3M

    ReplyDelete
  21. ID:-201610058
    1.https://drive.google.com/open?id=0B7UQyRdu6h2wbDNZYXF4blFUQnM

    ReplyDelete
  22. ID# 201610288
    Section A, Summer 2017
    https://drive.google.com/open?id=1CmKVL1SrFVzk027orxp4kl1dq9QbydNejKCCoZlI_dA

    ReplyDelete
  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;
    }

    ReplyDelete