-->
Showing posts with label .... 20th term.. Show all posts
Showing posts with label .... 20th term.. Show all posts

program to get Fibonacci series 1,1,2,3,5,8,.... 20th term.

using codeblocks
-----------------------------------------------------------------------------------------------------
//program to get Fibonacci series 1,1,2,3,5,8,.... 20th term.

#include <stdio.h>  //header file
void fibonacci();//function prototype
int main()                 //main function
{
    fibonacci();          // function calling
    return 0;             // returning 0 value
}

void fibonacci()      //function body line/definition
{
    int a=1,b=1,c,i;       // initializing value 1
    printf("%d\n%d\n",a,b);// display of those value
    for(i=1;i<=18;i++)     // running loop for 18 times
    {
        c=a+b;            // finding sum of two numbers
        printf("%d\n",c);//display of that sum
        a=b;             //assigning b to a and c to b.
        b=c;
    }
}


----------------------------------------------------------------------------------------------------------
using turboc++
-----------------------------------------------------------------------------------------

//program to get Fibonacci series 1,1,2,3,5,8,.... 20th term.

#include <stdio.h>  //header file
#include<conio.h>//header file
void fibonacci();//function prototype
int main()                 //main function
{
    fibonacci();          // function calling
    getch();             //holds the output
}

void fibonacci()      //function body line/definition
{
    int a=1,b=1,c,i;       // initializing value 1
    printf("%d\n%d\n",a,b);// display of those value
    for(i=1;i<=18;i++)     // running loop for 18 times
    {
        c=a+b;            // finding sum of two numbers
        printf("%d\n",c);//display of that sum
        a=b;             //assigning b to a and c to b.
        b=c;
    }
}