Blog Moved

This website completely moved to new domain. For latest content, visit www.programmingposts.com

Search This Blog

5 Aug 2012

C program to print Fibonacci series upto N th term


/* C program to generate and print Fibonacci series */
#include<stdio.h>
main()
{
int n,i,a=0,b=1,c=0;
printf("Enter Nth term of Fibonacci series : ");
scanf("%d",&n);
printf("\n %d %d ",a,b); //for printing first two numbers
for(i=2;i<n;i++)  // for printing from 3rd number in series
{
 c=a+b;
 a=b;
 b=c;
 printf("%d ",c);
}
 printf("\n\n");
return(0);
}

Output: ( using GNU GCC Compiler with Code Blocks IDE )

4 comments:

  1. can you also tell how can i find nth number of this series if that is not given

    ReplyDelete
    Replies
    1. hi stayam,
      Here, Loop will continue based on n value, so you need n number to print the series.

      Delete
  2. Very informative article.Thank you author for posting this kind of article .

    http://www.wikitechy.com/view-article/Fibonacci-series-program-in-cpp


    Both are really good,
    Cheers,
    Venkat

    ReplyDelete