/* 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 )
can you also tell how can i find nth number of this series if that is not given
ReplyDeletehi stayam,
DeleteHere, Loop will continue based on n value, so you need n number to print the series.
Great Work.. I saw One more easiest way to
ReplyDeleteWrite a C Program To Print Fibonacci Series
Very informative article.Thank you author for posting this kind of article .
ReplyDeletehttp://www.wikitechy.com/view-article/Fibonacci-series-program-in-cpp
Both are really good,
Cheers,
Venkat
nice article .thank you for sharing useful info.
ReplyDeleteweb programming tutorial
welookups