Fibonacci challenge

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

38 Replies - 33192 Views - Last Post: 21 February 2015 - 06:49 AM

#31 p.mo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • 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

Was This Post Helpful? 1
  • +
  • -

#32 HB-aka  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • 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.

Was This Post Helpful? 0
  • +
  • -

#33 tifuy95  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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;
}


Was This Post Helpful? 0
  • +
  • -

#34 compscistud  Icon User is offline

  • New D.I.C Head

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

Re: Fibonacci challenge

Posted 18 November 2014 - 01:20 AM

this was my assignment last week lol
Was This Post Helpful? 0
  • +
  • -

#35 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 731
  • View blog
  • Posts: 2,565
  • Joined: 31-December 10

Re: Fibonacci challenge

Posted 18 November 2014 - 12:04 PM

View Posttifuy95, 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.
Was This Post Helpful? 0
  • +
  • -

#36 9644026902  Icon User is offline

  • New D.I.C Head

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

Re: Fibonacci challenge

Posted 27 November 2014 - 08:03 AM

Spoiler

This post has been edited by Skydiver: 22 January 2015 - 10:48 PM
Reason for edit:: Put code in spoiler tags.

Was This Post Helpful? 0
  • +
  • -

#37 fj_j_greenhalgh  Icon User is offline

  • New D.I.C Head

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

Re: Fibonacci challenge

Posted 05 December 2014 - 06:04 PM

Template Metaprogramming C++11

Spoiler

This post has been edited by Skydiver: 22 January 2015 - 10:47 PM
Reason for edit:: Put code in spoiler tags.

Was This Post Helpful? 0
  • +
  • -

#38 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3921
  • View blog
  • Posts: 12,425
  • Joined: 05-May 12

Re: Fibonacci challenge

Posted 22 January 2015 - 10:47 PM

fj_j_greenhalgh: See post #27.
Was This Post Helpful? 0
  • +
  • -

#39 its_MCD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-February 15

Re: Fibonacci challenge

Posted 21 February 2015 - 06:49 AM

I found a way to make a function for fibonacci's formula by using ading ect.
int fibonacci(){
    unsigned long long int nom1 = 0;
    unsigned long long int nom2 = 1;


    while(nom2 < 999999999){
        printf("%d \n",nom1 + nom2);
        int nom3 = nom1 + nom2;
        printf("%d \n",nom2 + nom3);
        nom1 = nom2 + nom3;
        printf("%d \n",nom3 + nom1);
        nom2 = nom3 + nom1;



    }


return 0;}


View Postits_MCD, on 21 February 2015 - 06:48 AM, said:

I found a way to make a function for fibonacci's formula by using ading ect.
int fibonacci(){
    unsigned long long int nom1 = 0;
    unsigned long long int nom2 = 1;


    while(nom2 < 999999999){
        printf("%d \n",nom1 + nom2);
        int nom3 = nom1 + nom2;
        printf("%d \n",nom2 + nom3);
        nom1 = nom2 + nom3;
        printf("%d \n",nom3 + nom1);
        nom2 = nom3 + nom1;



    }


return 0;}
sorry i don't know how the code should come
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3