Home » Display fibonacci series upto Nth term

Display fibonacci series upto Nth term

Learn about Display fibonacci series upto Nth term in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Contents

Display fibonacci series upto Nth term

Program:

#include<stdio.h>
void fibonacciSeries(int n)
{
   int a=0, b=1, c;
   for(int i=0; i<n; i++)
   {
     printf("%d\t", a);
     c = a+b;
     a = b;
     b = c;
   }
}

int main()
{
   int term;

   printf("Enter the term: ");
   scanf("%d", &term);

   printf("The fibonacci series is: \n");

   fibonacciSeries(term);

   return 0;
}

Output:

Enter the term: 5
The fibonacci series is:
0 1 1 2 3

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
Display Fibonacci series in C within a range using a function
C Program to Find Grade of a Student using Function and switch case