# Fibonacci challenge

• (3 Pages)
• 1
• 2
• 3

## 36 Replies - 30544 Views - Last Post: 05 December 2014 - 06:04 PM

### #31 p.mo

Reputation: 1
• Posts: 1
• Joined: 02-October 12

## Re: Fibonacci challenge

Posted 02 October 2012 - 07:58 PM

This is my first post and challenge. While its not very compact should be functional functional.

Spoiler

### #32 HB-aka

Reputation: 0
• Posts: 62
• Joined: 03-June 14

## Re: Fibonacci challenge

Posted 09 June 2014 - 03:02 AM

this function will get Fibonacci numbers.
i used "long integers" because the number can get to big.
so...this is the code i'v made.
Spoiler

This post has been edited by Skydiver: 09 June 2014 - 08:22 PM
Reason for edit:: Put code in spoiler tags to keep challenge fresh for late comers.

### #33 tifuy95

Reputation: 0
• Posts: 1
• Joined: 26-September 14

## Re: Fibonacci challenge

Posted 26 September 2014 - 11:20 AM

I am a new programer can someone give me feedback on my code??
```// Made by Max Bentata

//09/21/2014

#include <iostream>
using namespace std;

int main()
{
int x = 0;
int fib = 0;
int sum = 1;
int marker = 0;

cout << x << endl;
x = fib + sum;
cout << x << endl;
fib = x + sum;
cout << fib << endl;

x = fib + sum;
cout << x << endl;

while (mkr < 15){
sum = x + fib;
cout << sum << endl;
fib = sum + x;
cout << fib << endl;
x = fib + sum;
cout << x << endl;
marker++;
}

return 0;
}

```

### #34 compscistud

Reputation: 0
• Posts: 17
• Joined: 21-October 14

## Re: Fibonacci challenge

Posted 18 November 2014 - 01:20 AM

this was my assignment last week lol

### #35 vividexstance

• D.I.C Lover

Reputation: 687
• Posts: 2,377
• Joined: 31-December 10

## Re: Fibonacci challenge

Posted 18 November 2014 - 12:04 PM

tifuy95, on 26 September 2014 - 01:20 PM, said:

I am a new programer can someone give me feedback on my code??
```// Made by Max Bentata

//09/21/2014

#include <iostream>
using namespace std;

int main()
{
int x = 0;
int fib = 0;
int sum = 1;
int marker = 0;

cout << x << endl;
x = fib + sum;
cout << x << endl;
fib = x + sum;
cout << fib << endl;

x = fib + sum;
cout << x << endl;

while (mkr < 15){
sum = x + fib;
cout << sum << endl;
fib = sum + x;
cout << fib << endl;
x = fib + sum;
cout << x << endl;
marker++;
}

return 0;
}

```

One thing that stood out for me is that you use what are called "Magic Numbers", specifically, the while(marker < 15). What is that 15 supposed to represent? Would it be used more than once if this were a larger program? If so, what happens when you want to change the 15 to something else? You would have to go through the code and replace the number and hope that you don't miss any, or if you do, that it will be noticed and easily found.

The tip, would be to use a variable, specifically, a const variable that doesn't change throughout the program. This way, you can give the number a descriptive name which helps people reading the code to understand it a little easier. Also, it makes changing/maintaining the code easier because you only have to make the change in one place instead of many.

### #36 9644026902

Reputation: 0
• Posts: 1
• Joined: 27-November 14

## Re: Fibonacci challenge

Posted 27 November 2014 - 08:03 AM

```#include<iostream.h>
int c=0;
int main(int j)
{
if(c==0)
{
clrscr();
c=1;
int i=0;
while(i<10)
cout<<main(i++)<<endl;
return 0;
}
else
{
if(j<1)
return 0;
else if(j==1)
return 1;
else
return main(j-1)+main(j-2);
}
}
```

### #37 fj_j_greenhalgh

Reputation: 0
• Posts: 1
• Joined: 05-December 14

## Re: Fibonacci challenge

Posted 05 December 2014 - 06:04 PM

Template Metaprogramming C++11

```#include <iostream>
#include <type_traits>

template<size_t _kX, size_t _kC, size_t _kN>
struct _FibonacciHelper;

template<size_t _kX, size_t _kC, size_t _kN>
struct _FibonacciHelper
: _FibonacciHelper<_kX-1, _kN, _kC+_kN> {};

template<size_t _kC, size_t _kN>
struct _FibonacciHelper<0,_kC,_kN>
: std::integral_constant<size_t,_kC> {};

template<size_t _kX>
struct Fibonacci
: _FibonacciHelper<_kX,0,1> {};

int main()
{
std::cout << Fibonacci<0>::value << std::endl;
std::cout << Fibonacci<1>::value << std::endl;
std::cout << Fibonacci<2>::value << std::endl;
std::cout << Fibonacci<3>::value << std::endl;
std::cout << Fibonacci<4>::value << std::endl;
std::cout << Fibonacci<5>::value << std::endl;
std::cout << Fibonacci<6>::value << std::endl;
return 0;
}

```