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 ...
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
}
}
Comments
MRA
NextDawn C and C++ Tutorials
The site you have provided is nice too. :)
-Echo
www.echo.net84.net
Also I have few info about the same on my blog
c-programming-tutorials.blogspot
http://www.a2zhacks.blogspot.com to learn C,C++,VB programming.
#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();
}
C interview questions
#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));
}
http://www.itstudentjunction.com/c-programs.htm
Payday Loans Online | Cash Advance Loans | Fast Cash Loans
#include
main()
{
char name[|XII+I|];
strcpy(name,"Nemo");
puts(name);
}
http://wininterview.blogspot.in/2013/01/sample-c-programs.html
instead of using loops. .Thanks, its really helped me......
-Aparna
Theosoft
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
C Programming
The program is a game played by a human versus the machine.
At the start, the prompt asks the human to enter three non-zero integers. These will constitute how many counters are in each Pile.
The machine then asks who goes first.
A turn consists of selecting a Pile and taking a number of counters from that pile.
For example, if the Piles contain 3, 7 and 12 counters, a legal move consists of taking from 1 to 3 from Pile 1, or 1, 2, … 7 from Pile2 etc.
The object of the game is to be the player to take the last counter(s). So if Piles contain 0 2 0, the player whose turn it is will take 2 from Pile 2 and win.
The program must play and optimal strategy so if it has a winning position it will win the game. If it does not have a winning position it should try to extend the game.
At the end of the game, the program must declare the winner.
snowflake interview questions and answers
inline view in sql server
a watch was sold at loss of 10
resume format for fresher lecturer in engineering college doc
qdxm:sfyn::uioz:
java developer resume 6 years experience
please explain in brief why you consider yourself suitable for the position applied for
windows 10 french iso kickass
max int javascript
tp link router password hack