Quiz #08 (Most important, final exam question #4)

--Originally published at OlafGC / Class #TC1017

Hello dear friends! A quick tutorial on how to solve the fourth question of the exam. I hope you find this very useful and thanks for watching!

Code:

#include <iostream>
using namespace std;

int fibonacci(int n)
{
int fib=1, pre=0;
for(int accu=0; accu<n; accu++)
{
fib+=pre;
pre=fib-pre;
} return fib;
}

int main()
{
int res,n;
cout<<“Dame número “<<endl;
cin>>n;
res=fibonacci(n);
cout<<“Tu fibonacci es “<<res<<endl;
return 0;
}


Fibonacci everywhere! #Quiz08

--Originally published at It&#039;s me

Fibonacci series… They’re quite interesting. Given a number the program will display all the fibonacci serie until the number the user gives, you’ll see the example in the code running. Basically I used the “formula” in this web page and with some help of a friend we could made it. We create the function fibonacci(int i) and the rest was just ifs and for. Here is the code:

quiz8Quiz08

Original header image recovered from: https://www.flickr.com/photos/ghirson/18475777/in/photolist-2CGcT-6GsoZ-oo7TWg-5Pimso-6b7s7N-c6pvt-pktg1Y-dkhaTG-2hdazR-2hhwkW-akkK66-akkK7P-akmSCP-4KyYUJ-6VNZjD-auoSAF-6eYwN-5HEX9f-o8z6-97N2Vr-nMkbeF-9bVtin-4cU5U8-ak7ZDH-akoxRN-dFPAm-akoxUL-5WDT8U-akaXwJ-ugXsf-8W8C2i-3X9rC1-4ikigj-dxvd-2RsTt1-dJ1bG4-akkK1M-QH7UF2-e9syey-jXn1k8-6MhYzd-5FE4R7-oqAfwT-ar66jF-hhA7Fs-7keK9r-8dqu3c-b1ecA-yjdnJ-9X1ET8


cout<<“Fibonacci number <<endl;

--Originally published at Alvaro_246

“Quiz Week 08”

En el Quiz de la semana numero 8, Trabajamos con la sucesión de Fibonacci e hicimos un programa que nos mostrara la seria de Fiboncci hasta un numero determinado que el usuario ingrese. Para ello hice una funcion llamada fibonacci la cual recibe un numero entero que va a ser igual al limite de la serie. void fibonacci(int numero){}. Dentro de la función puse un “while” con la condición de que el numero que ingrese el usuario no puede ser <0. La funcion fibonacci contiene la siguiente formula para la serie de Fibonacci :

while(Base <=numero){
cout << Base << “,” ;
x1 = x2;
x2 = Base;
Base = x1 + x2;
}

Fibonacci

Código y Resultados:

2017-03-12 (5)2017-03-12 (6)


Fibonacci

--Originally published at Ken&#039;s Disciple 01

Picture by Unsplash Unsplash

 

Hello everyone! Welcome to Quiz 08’s Blog post. In this quiz we actually had to do two programs about the same thing, giving the ‘nth’ fibonacci number. This program was actually very easy to do if you had the correct information. So the first program was about doing a loop and the second one was doing a recursion, which basically is doing a function that calls itself (I know it sounds weird, but you should probably check the book, check where it says recursions).

I highly recommend reading the book (because it also gives the example of fibonacci numbers with recursions, it’s section 5.12) and also if you want your program to support a wider range of values you may want to use long long variables and also unsigned, which basically means that the variable won’t work with negative numbers; giving you more space to work with positive numbers.

So let’s get started, here are my two programs:

Captura de pantalla 2017-03-07 a la(s) 11.29.30.png

Captura de pantalla 2017-03-07 a la(s) 11.28.55.png

Captura de pantalla 2017-03-07 a la(s) 11.28.10.png

Captura de pantalla 2017-03-07 a la(s) 11.28.26.png

As you may have seen I timed both programs in order to conclude this: The recursion program may look more “elegant”, since it’s smaller and also may be easier to understand, and it may occupy less space in memory. Also the loop one is more “efficient”, since it takes less time to perform the calculations, and believe me, if you try with bigger numbers time will be way faster with the loop one. So in conclusion, I think that the space we will save with recursions is not that much of a difference as time, so I thing the loop one is the better one to work with.

As always my codes at GitHub:
Loop
Recursion

If you have questions, feel free to ask.

 

l.out


Code Strange

--Originally published at Adal´s Blog

Resultado de imagen para dr strange buildings



La actividad de hoy involucra dos formas diferentes de hacer lo mismo:


Para resolver el la primera opción me ayude de un ejemplo que esta en el libro 

Y el resultado fue:

Para hacerlo en forma de loop utilice 4 variables para ayudarme a llevar un contador y la suma de lo contado 

Paginas de ayuda:

#Quiz08 See the algorithm of Fibonacci serie explained!

--Originally published at Solving Problems with Programming

PICTURE OF AUTOR

THIS IS THE #QUIZ8 WHOSE OBJECTIVE IS CREATE AND CALL FUNCTIONS TO DO DIFFERENT TASKS AT DIFFERENT TIMES USING RECURSION AND LOOPS. COVERING #MASTERYTOPIC06 #MASTERYTOPIC07 . This IS ALSO to fulfill the #Mastery12 Use of recursion for repetitive algorithms

This #QUIZ08 makes first a survey where I gave some advice or feedback to ken bauer in how i am learning in this course. Next, in this quiz 8 makes a function that calculates  and returns the “nth” Fibonacci number where we define a function over the Fibonacci numbers mapping the naturals (starting with zero) to the Fibonacci series.

fibo2

Link of the picture:Link of the picture

So fibonacci(0) returns 0, fibonacci(1) returns 1, fibonacci(2) returns 1 and so on. Note that we are using the modern definition where the sequence starts with zero. I tried to implement this with two solutions: one with a loop and one with recursion. Which do I think is “better”, which looks more “elegant”, which is more “efficient”?

First let me show you the pictures of the quiz:

fibo3

fibo4fibo5

FIRST TO DO IN THIS #QUIZ08 with the recursion solution is writing a function called ‘fibonacci(int n)’ with an int parameter called n where this parameter is the value of the list in the serie.

Inside of this function, we have a condition a #Mastery10 use of the if statement. This command allows the condition if the value of n is equal to 0 or 1 when this condition will be true, the tasks inside of the statement will execute. In this case if the value of n is equal than 0 or 1 this will occur:

return n; //With this command you return the value of the int variable n in order to show it in THE MAIN FUNCTION

return n; //With this command you return the value of 
Continue reading "#Quiz08 See the algorithm of Fibonacci serie explained!"

Quiz 08

--Originally published at TC1017

The quiz from week 8 consisted in creating a program that returned the value typed by the user of the fibonacci series. Ken gave us a very clear explanation of how the series worked and it was pretty easy to deduce how the program would work. I spent half of the class debugging the code and making sure the values were correct. The code is below.

 

quiz8.pngquiz81.png


This is getting hard….

--Originally published at my programming blog

Today I had to do the quiz #8 which was to create a function where I needed to calculate the nth number in the Fibonacci sequence. I had a lot of trouble with this quiz!!!!! I didn’t go to class, so I couldn’t ask to my classmates or to Ken, so I searched for a lot of examples and tutorials of different codes for this program and with what I understood I created my own program.

What I did was:

  1. In my function I only declared one value x, which will be the number the user will enter.
  2. Then I made an if that if x was equal to something less than 2, then the fibonacci number would be x.
  3. Then I declared 3 values, n1, n2 and n, where n1 is 0 (the first fibonacci number) and n2 is 1 (the second fibonacci number) and n the total value of the fibonacci number we will calculate.
  4. Then I did a for loop and as you can see on the code I equal n to n1 + n2, n1 equals n2, and n2 equals to n (This are the operations to obtain the fibonacci number).
  5. And the return value was n.
  6. The in my int main I asked the user for the value of a number in the fibonacci sequence which is the integer value.
  7. Then to print the number I called the function but I changed the inside of the parenthesis to the int value so that the fibonacci number can be calculated based on the value the user entered.
  8. And that’s it.

I hope you understand it! If not here are some examples of different codes and a tutorial that can give you an idea to create your own code. Also check the work of our classmates in

Screen Shot 2017-03-02 at 10.37.04 PM.png
screen-shot-2017-03-02-at-10-53-17-pm
Continue reading "This is getting hard…."

Fibonacci series- quiz week 8

--Originally published at Programming course

5978831814_69fd0027af_o fib

 

In this assignment we saw the number series of Fibonacci, which is basically a mathematical explanation to many things in nature, such as the spirals found in flowers, plants, etc, and the numerical sequence in them.  In the program we made, using a loop I told the user the series. This is the code I used.

And if you want to know more about Fibonacci in art, you can click here and there is a great  easy slideshow.quiz8quiz8-atom

Pictures used:

https://www.flickr.com/photos/snlsn/

http://www.imagekind.com/Hokusai-Meets-Fibonacci-Golden-Ratio_art?IMID=87c29c1e-7700-45a0-ae29-6b7ddcbf7e48


Quiz Week 8

--Originally published at Let&#039;s CODE

This class we were oredered to write a code that generates the Fibonacci series. I was a really challenging task, ’cause my logic didn’t adapted to the situation righly. Finally I used some loops, vectors and a function to make it work. This is what I wrote. #include <iostream> using namespace std; int fibonacci(int n) … Continue reading Quiz Week 8