Fibonacci Series - Devbhoomi

FREE JOB ALERT & ONLINE TUTORIALS

Hot

Post Top Ad

Tuesday 7 November 2017

Fibonacci Series

#include <stdio.h>

int main()
{

    int a, b, c, i, n;

    a = 0;
    b = 1;

    printf("Enter a number to define the length of fibonacci series: ");
    scanf("%d", &n);
    printf("\nThe Series is: \n");
    printf("%d\t%d", a, b);

    for (i = 0; i < n; i++)
    {

        c = a + b;

        a = b;

        b = c;

        printf("\t%d", c);

    }

    return 0;
}
OUTPUT
Enter a number to define the length of fibonacci series: 5

The Series is: 
0 1 1 2 3 5 8

No comments:

Post a Comment

Post Top Ad