View Full Version : Fibbonaci Series
ashvala
August 2nd, 2007, 05:36 PM
This Ain't my home work...
How many of you can write a program for Fibbanoci series in CPP?
LaRoza
August 2nd, 2007, 05:46 PM
This Ain't my home work...
How many of you can write a program for Fibbanoci series in CPP?
Many can, actually, anyone who know what that series is can.
Are you asking for code?
(http://answers.yahoo.com/question/index?qid=20060807231437AADyZGU)
mgoblue
August 2nd, 2007, 05:49 PM
Yeah it's pretty simple. Try the "golden ratio" using recursion.
fazavon
August 2nd, 2007, 05:51 PM
using namespace std;
unsigned long fibo(unsigned long n, unsigned long x)
{
long sum;
cout << x << " ";
sum=n + x;
if (n < 2147483647)
{
return sum + fibo(x,sum);
}
else
{
return x;
}
};
int main(int argc, char* argv[])
{
int y;
fibo(0,1);
cin >> y;
return 0;
}
Jessehk
August 2nd, 2007, 06:13 PM
This Ain't my home work...
I don't believe you. :)
Here's a template metaprogramming one in D
import std.stdio;
template fib(uint n) {
static if ( n < 2 )
const uint fib = 1;
else
const uint fib = fib!(n - 2) + fib!(n - 1);
}
void main() {
writefln( "%s", fib!(45) );
}
LaRoza
August 2nd, 2007, 06:21 PM
I don't believe you. :)
Here's a template metaprogramming one in D
import std.stdio;
template fib(uint n) {
static if ( n < 2 )
const uint fib = 1;
else
const uint fib = fib!(n - 2) + fib!(n - 1);
}
void main() {
writefln( "%s", fib!(45) );
}
That is a good idea, can't copy and paste. (If it isn't homework)
If it IS homework, you get a faster result googling you question, "Program for Fibbonaci Series" will get you more. It will even fix your typo.
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.