C program to Print Fibonacci series

Write a program in the C programming language to print Fibonacci series up to the inputted number by using for loop statement. Below is the solution of the C program –

/* C program to print the fibonacci series*/
#include<stdio.h>
main()
{
     int f1,i,f2,f3,n;
      f1=0;
      f2=1;

      printf("upto which no.you want series");
      scanf("%d",&n);
      printf("%d \t %d \t",f1,f2);
      for(i=2;i<n;i++)
      {
              f3=f1+f2;
              f1=f2;
              f2=f3;
              printf("%d\t",f3);
      }
      getch();
}

Description – For loop is used to print the series up to n. First two terms of the Fibonacci series are initialized in the compile time initialization and from the first two terms the rest of the terms are created. After creating the new term ‘ f3 ‘; it is printed. The value of the new term and it’s previous term is stored in ‘ f2 ‘ and ‘ f1 ‘ so that the next new term can be created from these variables.
Input – 12
Output – 0   1   1   2   3   5   8   13   21   34   55   89

yashan has written 70 articles

3 thoughts on “C program to Print Fibonacci series

  1. Fanny says:

    2 décembre 2011Je trouve ça très chiant d’avoir un ajout automatique des groupes, j’ai plus de 1000 &lbp;ou&nasq;amis » et tous les jours j’ai le droit à un groupe de plus, du plus farfelu au plus inutile. Personnellement ça me gonfle !

Cancel reply

Leave a Reply to mahe

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>