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

C Program To Find Fibonacci Series Upto n Term (Using For Loop)

Algorithm

  1. Program Start
  2. Declaration of variable a=-1, b=1,c,n
  3. Enter a number
  4. Assign the value in variable
  5. Check condition
  6. Give answer according to condition
  7. Program End

Flowchart

Flowchart - C Program To Find Fibonacci Series

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

  1. Program Start
  2. Variable Declaration
  3. Input value
  4. Assign the value in variable
  5. Calling Function to find fibonacci series
  6. Check condition
  7. Give answer according to condition
  8. 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

  1. Program Start
  2. Declare Variable
  3. Input Number
  4. Assign Number into variable
  5. Calling Recursive Function to find Fibonacii series
  6. 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

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.

Jeetu Sahu is A Web Developer | Computer Engineer | Passionate about Coding, Competitive Programming, and Blogging

Leave a Comment

Ads Blocker Image Powered by Code Help Pro
Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Refresh
Powered By
CHP Adblock Detector Plugin | Codehelppro