Jump to content

Need help Fibonacci series C language

Venum

I want in depth idea on displaying the next three numbers in the fibonacci series. it doesnt matter if its a long series of fibo numbers as long as the three maybe starting numbers is printed out.

Link to comment
Share on other sites

Link to post
Share on other sites

What do you mean with "without inputing any integer but instead directly calculates the next three numbers"? The next three numbers to what?

 

The general form for a fibo series is starting with the base cases:

fib(0) = 0fib(1) = 1 And getting the next elements with:fib(n) = fib(n-2) + fib(n-1), n > 1

So if you want to get the first 10 fibonacci numbers:

int sequence_sz = 10; //first 10 fibonacci numbersint fib[sequence_sz];if(sequence_sz > 0){     fib[0] = 0;     if(sequence_sz > 1) fib[1] = 1;     for(int i = 2 ; i < sequence_sz ; i++) fib[i] = fib[i-2] + fib[i-1];}

Want to solve problems? Check this out.

Link to comment
Share on other sites

Link to post
Share on other sites

Could you elaborate on what you are trying to achieve?

@wolfsinner's post is indeed the general form of the Fibonacci sequence, if you mean something else you will have to formulate it in a different way so it is understandable for the people trying to help you.

Learning

Link to comment
Share on other sites

Link to post
Share on other sites

I have seen some formulate a code that ask a user to input a number. i wanted to omit that option and directly calculate the asked output.. im so confused T.T

Link to comment
Share on other sites

Link to post
Share on other sites

I have seen some formulate a code that ask a user to input a number. i wanted to omit that option and directly calculate the asked output.. im so confused T.T

The number is needed for input, so that you can choose what you want to output (e.g. the first 100 fibonacci numbers).

If you omit that, the output will be the same all the time.

If you are still confused you might want to read this: https://en.wikipedia.org/wiki/Fibonacci_number

Link to comment
Share on other sites

Link to post
Share on other sites

I have seen some formulate a code that ask a user to input a number. i wanted to omit that option and directly calculate the asked output.. im so confused T.T

There is not an obvious end of the Fibonacci sequence. That is why most of the time the user will be prompted to manually submit an end. What they say is the end, e.g. 3, represents the third number in the Fibonacci sequence. The program will then calculate all the numbers in the sequence until 3 (including, I assume). If you not set an end, it will go on until it hits an error because the number you're trying to store in the data type you used is too large.

You can hard code the end into your code, if that is what you mean, I can not give some code examples right now as I am on a mobile device, but here is the hard coded end:

for (int i = 1; i <= 3; i++)

If some of what I said is incorrect, please improve me :)

Learning

Link to comment
Share on other sites

Link to post
Share on other sites

Oh, the code does not seem to be displayed properly.

for (int i = 0; i <= 3; i++)

Learning

Link to comment
Share on other sites

Link to post
Share on other sites

Wow, why does it still not display properly? Oh well, you'll have to ask someone else for some code snippets.

Learning

Link to comment
Share on other sites

Link to post
Share on other sites

Oh, the code does not seem to be displayed properly.

Code tags brah

 

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

Code tags brah

Tapatalk does not want to let me use code tags... Oh wait.. Ugh I am so stupid :P

for (int i = 0; i <= 3; i++)
There you go.

Learning

Link to comment
Share on other sites

Link to post
Share on other sites

Here you go.. This will print forever

 

C++

#include <iostream>using namespace std;int a = 0, b = 1, c = 0:void main() {        cout << 1 << endl;	while(true){		c = a + b;		a = b:		b = c;		cout << c << endl;	}}

CPU: i7 4770k | GPU: Sapphire 290 Tri-X OC | RAM: Corsair Vengeance LP 2x8GB | MTB: GA-Z87X-UD5HCOOLER: Noctua NH-D14 | PSU: Corsair 760i | CASE: Corsair 550D | DISPLAY:  BenQ XL2420TE


Firestrike scores - Graphics: 10781 Physics: 9448 Combined: 4289


"Nvidia, Fuck you" - Linus Torvald

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×