Fibonacci series in c :

Fibonacci series that present a list of series of a number in this Fibonacci series we print at least two number 0,1 and then after this two number generate a new number using sum method. for example i want to print Fibonacci series of 4 number then we take two variable a,b and initialize a=0,b=1.

we print the value of a without taking condition a=0

and now we will use loop methods till 4 and in next(variable) assign the sum of a and b such as next=a+b.

then we assign the value of b with a and assign the value of next with b

#include<stdio.h>

#include<conio.h>

void main()
{
int i, a = 0, b = 1,next=0;

for (i = 1; i <= 9; ++i) {
    printf("%d, ", a);
    next = a + b;
    a = b;
    b = next;
}

getch();
}

Output: 0 1 1 2 3 5 8 13 21

Categories: c language

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *