In this quiz we had to make a program that tells you the greatest common divisor between two integer numbers. So the program asks for the biggest number and then the smallest.
For this we have to use the Euclid’s Algorithm: (Wikipedia obviously)
The Euclidean algorithm is based on the principle that the greatest common divisor of two numbers does not change if the larger number is replaced by its difference with the smaller number. For example, 21 is the GCD of 252 and 105 (252 = 21 × 12 and 105 = 21 × 5), and the same number 21 is also the GCD of 105 and 147 = 252 − 105. Since this replacement reduces the larger of the two numbers, repeating this process gives successively smaller pairs of numbers until one of the two numbers reaches zero. When that occurs, the other number (the one that is not zero) is the GCD of the original two numbers.
Here is a video, it´s in Spanish but explains this quite good:
Thanks to Baruch who taught me how to make the loop.
In this quiz, first we have to create a program that calculates the distance between two point in a graph using the coordinates (X, Y).
The user has to introduce the two points (X1, Y1) and (X2, Y2).
In the second program we have to do the Fibonacci sequence using just one input.
The Fibonacci sequence are the numbers in the following integer sequence.
0, 1, 1, 2, 3, 5, 8, 13, 21, …
By definition, the first two numbers in the Fibonacci sequence are either 1 and 1, or 0 and 1, depending on the chosen starting point of the sequence, and each subsequent number is the sum of the previous two.
Also, the program ask the user if he wants another number of the sequence.
In the first exercise we had to ask for two numbers (a, b) and show the result of growing the first one to the second one. Example: (a=5, b=2) R=25
We could do this with the function Pow including the <math.h> library, or we can do it with the function For. I did it with Pow:
In the second exercise we had to show the number of stars that we ingress. Example: cin=5 R=*****