Fibonacci series in C.

 Fibonacci series  :  Fibonacci series is a sequence of numbers, starting with zero and one is create by adding or sum of previous two numbers.

Series like 0, 1, 1, 2, 3, 5, 8, 13, 21 ......................

In this c program I can take initial value a = 1 and b = 1

// program of fibonacci series
#include<stdio.h>
#include<conio.h>
int main()
{
    int a,b,c,term;
    a=1;b=1;
    printf("Enter number of term you print:\n");
    scanf("%d",&term);
    printf("%d\t%d\t",a,b);
    while(term-2>0)
    {
        c=a+b;
        a=b;
        b=c;
        printf("%d\t",c);
        term--;
    }
    return 0;
}

Output :-
Enter number of term you print: 8 1 1 2 3 5 8 13 21

same by using function

// program of fibonacci series
by using function 1,1,2,3,5,8....
#include<stdio.h>
#include<conio.h>
int fibo(int,int); // prototype
deleration
int main()
{
    int a,b,c,term;
    a=1;b=1;
    printf("Enter number of term
you print:\n");
    scanf("%d",&term); // enter
term you can print
    printf("%d\t%d\t",a,b); // print
first two term
    while(term-2>0) // work at term -2
terms like 5 when 5-2 =3
    {
        c=fibo(a,b); //function call
        a=b;
        b=c;
        printf("%d\t",c);
        term--;
    }
    return 0;
}
int fibo(int x,int y)//function defination.
{
    return(x+y);
}

Output :-
Enter number of term you print: 8 1 1 2 3 5 8 13
21

******* Thank you ******

Comments

Popular posts from this blog

5 d.) program to print this :