Fibonacci Series program in C

Fibonacci series starts with 0 and 1.The third element of fibonacci series in obtained by adding the first,two elements of the series.If we need to find an element of the series we add the two numbers which are just behind it.We can generalize the equation as,the nth element of the series is obtained by adding n-1 and n-22,1 element of the series.

Let us see an example…..As we know the first two elements are 0 and 1.The third element of the series is obtained by adding 0 and 1,hence the third element is 0+1=1.Therefore the series would be 0,1,1…Fourth element of the series is addition of second and third element….i.e 1+1=2..hence the fourth element is 2 and series will be 0,1,1,2….

By observing the program we need to change the values of a and b repeatedly…..because we need to add two values behind to it.In the below program the input is an integer which is length of the series.

void main()
	int a=0,b=1,c,i,n;
	printf("\t\t*********Fibonnaci series************");
	printf("\nEnter number of terms need to be present in the series:");
	printf("\n%d  %d  ",a,b);
		c = a+b;
		printf("%d  ",c);

Download the source code.

About Anuroop D

Very enthusiastic about technology and likes to share my knowledge through blogging. Has Bachelor's in Information Technology and currently pursuing my PhD in Computer Science.
This entry was posted in C and tagged , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s