skip to main |
skip to sidebar
###
Generation of Fibonacci Sequence using Recursion.

Write a recursive function to obtain the first 25 numbers of a Fibonacci sequence. In a Fibonacci sequence the sum of two successive terms gives the third term. Following are the first few terms of the Fibonacci sequence:1 1 2 3 5 8 13 21 34 55 89 ...

**#include<stdio.h>**

main()

**{**

**static** **int** prev_number=0, number=1; // **static**: so value is not lost

**int** fibonacci (**int** prev_number, **int** number);

printf ("Following are the first 25 Numbers of the Fibonacci Series:\n");

printf ("1 "); //to avoid complexity

fibonacci (prev_number,number);

**}**

fibonacci (**int** prev_number, **int** number)

**{**

**static** **int** i=1; //i is not 0, cuz 1 is already counted in main.

**int** fibo;

**if** (i==25)

**{**

printf ("\ndone"); //stop after 25 numbers

**}**

**else**

**{**

fibo=prev_number+number;

prev_number=number; //important steps

number=fibo;

printf ("\n%d", fibo);

i++; // increment counter

fibonacci (prev_number,number); //recursion

**}**

**}**

## 38 comments:

Thanks for this example!

MRA

NextDawn C and C++ Tutorials

Thanks. :)

The site you have provided is nice too. :)

it should be more clear

thanks

IF THE PROGRAM USED POINTER CONCEPTS THEN IT 'LL BE MOST USEFUL

Thanks a lot!

-Echo

www.echo.net84.net

Thanks alot ... it seems to be pretty clear nad would need some more example if possible.

Also I have few info about the same on my blog

c-programming-tutorials.blogspotthanks a lot sir for your help

Thanks for the idea

Thanks for the idea

thnx... datz gud 1,

become a follower for free C,C++ And vb code of my blog:

http://www.a2zhacks.blogspot.com to learn C,C++,VB programming.

Thank u

many many thanx for example....please continue providing more examples in functions

thanks.. very easy coding for this program..easily understable..

many many thanks for the example

#include

#include

int fabo(int);

int main()

{

int result=0,a=1,b=1,c,i;

printf("enter upto which you want to generate the series");

scanf("%d",&c);

for(i=c-1;i>=0;i--)

{result=fabo(c-i);

printf(" %d",result);}

getch();

}

int fabo(int n)

{

int i;

if (n==1)

return 1;

if(n==2)

return 1;

else

return (fabo(n-1)+fabo(n-2));

getch();

}

Rajat its good...

thanks you so much this helped me a lot.. :D

Thanks for the example very well explained. Infact this site sholud be opened first when the google is surfed

the variable a=1 and b=1????is for???

This is awesome post and good imformation

C interview questions

#include

#include

int fabo(int);

int main()

{

int result=0,c,i;

printf("enter how many no. you see:");

scanf("%d",&c);

for(i=c-1;i>=0;i--)

{result=fabo(c-i);

printf(" %d",result);}

getch();

}

int fabo(int n)

{

int i;

if (n==1)

return 1;

if(n==2)

return 1;

else

return (fabo(n-1)+fabo(n-2));

}

find largest database of c programs at

http://www.itstudentjunction.com/c-programs.htm

Realy good job, i found your blog from google search, I impressed, i bookmark this blog for future

thanks , i think c is simple and easy language...

Payday Loans Online | Cash Advance Loans | Fast Cash Loans

http://ccppcoding.blogspot.in/

#include

#include

main()

{

char name[|XII+I|];

strcpy(name,"Nemo");

puts(name);

}

very simple and cool programs at

http://wininterview.blogspot.in/2013/01/sample-c-programs.html

Appreciation for nice Updates, I found something new and folks can get useful info about BEST ONLINE TRAINING

Hi, Nice Program to calculate the factorial of a number. Use the concept of recursion

instead of using loops. .Thanks, its really helped me......

-Aparna

Theosoft

To know the programming technique: "Make Your Program Trial Version in C" visit:

udebayan.blogspot.com

This blog is awesome,thanks for ur valuable inforamtion ,u want more inforamtion about C programming languages join C programming classes in bangalore,visit : Aptech computer education,my tage are :

C training bangalore,C courses bangalore,C classes bangalore,C institute bangalore,C coaching centers bangalore,C programming institute in bangalore,C programming classes in bangalore

What you get from RSC Bux - Main Benefits :

Reach millions of clients

Easy management

Demographic filter

Affordable rates

Anti-cheat protection

Detailed statistics

bux

the rsc bux

advertising

perfect money

get Free Money Online

Thank you for posting the great content……I found it quiet interesting, hopefully you will keep posting such blogs…We are the best share market tips provider and we are providing best copper tips

Very Useful Post!Thanks!

C Programming

Post a Comment