Fibonacci series up to n using C

Write a C program to find Fibonacci series up to n

C program for Fibonacci series using a for loop statement. Numbers of these(0,1,1,2,3,5,8,…) sequence are known as Fibonacci numbers.

The sequence is a Fibonacci series where the next number is the sum of the previous two numbers. The first two terms of the Fibonacci sequence is start on 0,1,…

Ex. limit is Fibonacci series 8
Sequence is 0,1,1,2,3,5,8,13
Its followed on addition operation. Next number is addition of before first two numbers .

Fibonacci series up to n in C programming(1)

Working:-

Step 1.Initialize variables limit, N1=0, N2=1, N3, i.

Step 2.To take user input for limit of serious.

Step 3.Display N1, N2 value .

Step 4.We use for loop with the condition(i=0;i<limit).

Step 5.Compute N3 = N1 + N2 and n1=n2.  && n2=n3.

Step 6.Than display N3 as output and close the loop

Step 7.Stop

C Program:-

#include<stdio.h>
int main()
{
//To initialize variables
int n1=0,n2=1,n3,limit,i;

//To take user input
printf("enter a limit of series \n");
scanf( "%d",&limit);

printf("Fibonacci series %d %d ",n1,n2);

//To use this loop for given length
for(i=2;i<limit;i++)
{
//n1 and n2 sum store in new variable n3
n3=n1+n2;
n1=n2;
n2=n3;
//display serious
printf("%d ",n3);
}
return 0;
}

Output:-

enter a limit of series

10

Fibonacci series  0 1 1 2 3 5 8 13 21 34

Please Login/Signup to comment