+ 2
when they say google is your friend: " a series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc." a simple code could look like this: int a=0; //variable to store first number to add int b=1;//variable to store second number to add int fibonacciLength=8;//desired length of the fibonacci series for (int i=0; i< fibonacciLength; i++){ int c=a+b;//variable to hold the sum the two numbers cout<<c;//print the sum a=b;//update first number for next calculation b=c//update second number for next calculation }// the for loop will repeat until the desired length of the series is complete
28th Dec 2016, 3:08 PM
seamiki
seamiki - avatar