C Program To Find Fibonacci Series (5 Different Ways)
In this article, we are going to write a c program to find Fibonacci series.
We will make this program in the following way -:
- C Program To Find Fibonacci Series Upto N Term (Using For Loop)
- C Program To Find Fibonacci Series Using While Loop
- C Program To Find Fibonacci Series Using Function
- C Program To Find Fibonacci Series Using Recursion
- C Program To Find Fibonacci Series Using Array
To make this program, we will use the following concept given below. If you do not know about these topics well, then you may not understand this program, so you should know about them in detail from the link given below.
Now without wasting time let’s start programming.
C Program To Find Fibonacci Series Upto n Term (Using For Loop)
Algorithm
- Program Start
- Declaration of variable a=-1, b=1,c,n
- Enter a number
- Assign the value in variable
- Check condition
- Give answer according to condition
- Program End
Flowchart
Program
//C Program To Find Fibonacci Series Using For Loop
#include<stdio.h>
int main()
{
//variable declaration
int a=-1,b=1,c,i,number;
//input number
printf("Enter the number : ");
scanf("%d",&number);
printf("Fibonacci Series : ");
for(i=1;i<=number;++i)
{
c=a+b;
printf(" %d",c);
a=b;
b=c;
}
return 0;
}
Output
Enter the number : 8
Fibonacci Series : 0 1 1 2 3 5 8 13
C Program To Find Fibonacci Series Using While Loop
Program
//C Program To Find Fibonacci Series Using While Loop
#include<stdio.h>
int main()
{
//variable declaration
int a=-1,b=1,c,i = 1,number;
//input number
printf("Enter the number : ");
scanf("%d",&number);
printf("Fibonacci Series : ");
while(i<=number)
{
c=a+b;
printf(" %d",c);
a=b;
b=c;
i++;
}
return 0;
}
Output
Enter the number : 5
Fibonacci Series : 0 1 1 2 3
C Program To Find Fibonacci Series Using Fuction
Algorithm
- Program Start
- Variable Declaration
- Input value
- Assign the value in variable
- Calling Function to find fibonacci series
- Check condition
- Give answer according to condition
- Program End
Program
//C Program To Find Fibonacci Series Using Function
#include<stdio.h>
void fibonacii(int number);
int main()
{
//variable declaration
int n;
//input number
printf("Enter the number : ");
scanf("%d",&n);
printf("Fibonacci Series : ");
fibonacci(n);
return 0;
}
void fibonacci(int number)
{
int a=-1,b=1,c,i;
for(i=1;i<=number;++i)
{
c=a+b;
printf(" %d",c);
a=b;
b=c;
}
}
Output
Enter the number : 10
Fibonacci Series : 0 1 1 2 3 5 8 13 21 34
C Program To Find Fibonacci Series Using Recursion
Algorithm
- Program Start
- Declare Variable
- Input Number
- Assign Number into variable
- Calling Recursive Function to find Fibonacii series
- Program End
Program
//C Program To Find Fibonacci Series Using Recursive Function
#include<stdio.h>
void printFibonacci(int n)
{
static int a=-1,b=1,c;
if(n>0){
c = a + b;
a = b;
b = c;
printf("%d ",c);
printFibonacci(n-1);
}
}
int main()
{
int n;
//input number
printf("Enter the number: ");
scanf("%d",&n);
printf("Fibonacci Series: ");
printFibonacci(n-0);
return 0;
}
Output
Enter the number: 12
Fibonacci Series: 0 1 1 2 3 5 8 13 21 34 55 89
C Program To Find Fibonacci Series Using Array
Program
//C Program To Find Fibonacci Series Using Array
#include<stdio.h>
int main()
{
int n,k;
int aray[20];
printf("Enter the number: ");
scanf("%d",&n);
aray[0]=-1;
aray[1]=1;
printf("\nFibonacci Series: ");
for(k=2;k<=n+1;k++)
{
aray[k]=aray[k-1]+aray[k-2];
printf(" %d",aray[k]);
}
return 0;
}
Output
Enter the number: 15
Fibonacci Series: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
Read More
- Download C Language Notes Pdf
- C Language Tutorial For Beginners
- C Programming Examples With Output
- 250+ C Programs for Practice PDF Free Download
Conclusion
So friends, in this article, we have written a c program to find Fibonacci series in this way.
- C Program To Find Fibonacci Series Upto N Term (Using For Loop)
- C Program To Find Fibonacci Series Using While Loop
- C Program To Find Fibonacci Series Using Function
- C Program To Find Fibonacci Series Using Recursion
- C Program To Find Fibonacci Series Using Array
If you have difficulty to understanding any program or have any doubts or questions, then tell me in the comment below.