Some useful info for you, if you don't already know it, is that each number in a fibonacci sequence is the sum of the two numbers preceding it, except for the starting number, which is a 1.
And if any other member of the forum will show the next fibonacci number then you can get all fibonacci numbers less than 100.:)
So my fibonacci number is
the thing is i know the series up to 100 but what i nid is either a loop or selection statement that will enable the computer to select or calculate the fibonacci series on its own up to 100
OP, so where is your code, we won't do your homework for you. You must have some knowledge of loops, unless you have been sleeping through the lectures. ;) I am not being sarcastic , you need to do somethings yourself - we look forward to helping out.
hello i have quited c++ a few months ago and now i am looking if i still can do anything of this language so ill have a try. the main concepts of the program will work i think.
is an infinite loop. It ends with the break statement, but that is a poor way of doing it. A better test expression might involve the number 100. A for loop is better.
for (i=0;i<arraysize;i++)
arraysize is 2, is this what you want - to just print the last two numbers?
it gets arraysize adds a number to the array, arraysize increases adds a number etc...
changed my code a bit:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int main(void)
{
int fibonacci [] = {0,1};
int arraysize=1;
while (fibonacci[arraysize-1]+fibonacci[arraysize]<=100) {
int arraysize=sizeof(fibonacci) / sizeof(int); //gets amount of items in array
fibonacci[arraysize]=fibonacci[arraysize-1]+fibonacci[arraysize-2];
}
for (int i=0;i<sizeof(fibonacci) / sizeof(int);i++)
{
cout << fibonacci[i] <<endl;
}
system("PAUSE");
return 0;
}
ofc you have to store them ...
it is a recursive sequence which means that the values are calculated by previous values. so if you don't store the previous values how would you calculate them ?you just say calc fib2 in comment but there is no explicit formula for fibonacci numbers