Fibonacci series in C

 What Febonacci series is

Discovered by the Italian mathematician Fibonacci. Sequence of numbers in which 1 appear twice as the first two numbers,and every subsequent number is the sum of two preceding numbers: 1,1,2,3,5,8,13 and so on. 

Let’s write a program which print febonacci series in C.

Step 1: let’s open turbo C and write the following code :

//Add preprocessor file

#include
#include

void main()
{
//declare variable
long int i,j,c,a,n;

//clear screen
clrscr();

printf(“enter range:”);
scanf(“%li”.&n);
printf(“enter first number :”);
scanf(“%li”,&i);
printf(“enter second number :”);
scanf(“%li”,&j);

for(a=0;a<n;a++)
{
c=i+j;
i=j;
j=c;

// print the result
printf(“ \n %li”,c);
}
getch();
}

1

Step 2: Now save it by pressing F2 then name it febonacci.cpp and click OK.

2

Step 3: Now compile it by pressing ALT+F9 or click on compile then click OK.

3

Step 4: Run the program by pressing ALT+R ,and see output.

Output:

4

I hope this article is helpful.

Happy Coding :)

Tags: