Quiz06

Instruction:

The function should receive two integers and return an integer.Obviously you should test your function, so create a main program that asks the user for two values, calculates the gcd and displays that.

 

Here is a link to the code in Github.

Python/Quiz6

Here is a picture of the code:

Quiz6

 

#Quiz 6

Hola hoy les traigo un programa que me recordo un poco a la primaria, bueno el chiste es que este tiene que sacarl el maximo comun divisor, de dos numeros dados por el usuario, gracias a que internet es una fuente basta de informacion encontre otro blog, si otro, que me dio informacion muy util para realizar mi codigo, como ya es tradicion en estos posts les adjunto fotos y links de referencias que les pueden servir.

Primero un poco de sabiduria:

En matemáticas, se define el máximo común divisor(MCD) de dos o más números enteros al mayor número entero que los divide sin dejar resto.

Captura de pantalla 2016-04-08 a las 1.41.33.png

Links de ayuda:

Quiz 6

https://es.wikipedia.org/wiki/M%C3%A1ximo_com%C3%BAn_divisor

Codigo:

https://github.com/OscarBaez/My-codes/blob/master/Quiz6.cpp

Hasta la proxima!

Quiz 6

En este quiz necesitabas crear un programa en donde se obtuviera el máximo común divisor de dos números que ingresara el usuario.

suena complejo pero gracias al algoritmo de Euclid se puede resolver, simplemente sigues al pie de la letra el algoritmo y funciona perfectamente. solo que es muy importante mencionar que si los dos números son 0 esto no puede ser definido.

code github

Quiz 6

Heeey there!!!!! Here’s my 6th quiz. Yup. I know It’s pretty late for it. I will reflect that on my rubric.

Aaaanyway, the fact is that the instructions were these: “Write a function to calculate the greatest common denominator of two positive integers using Euclid’s algorithm.”

Here’s the page if you want to check what’s the Euclid’s algorithm about: https://www.khanacademy.org/computing/computer-science/cryptography/modarithmetic/a/the-euclidean-algorithm

quiz601

So, here’s my code. Do you see the red chart? Dont’t do something like that. Your code won’t work.

I visited Emanuel’s blog and it was really helpful. I was kind of lost with this code.

I’ll be submitting a flowchart to explain it better.

Here’s my code if you want to check it out. Have a nice day!!!

https://drive.google.com/open?id=0BxQYx0WBiNoRYjZCeDJQemdXZTA

:)

 

 

GCD: What were you?

#TC1017 #QUIZ6

Soooo I had no idea what a GDC was, well I had forgotten what it was. Lucky for me Euclide’s formula was quite easy to understand anfd implement, so I chose to do it with arrays, just cause.

It was simple and effective, but I did struggle with a compiling error that was due to a bad implementation of some logic. (When either number is 0). I just had to rearrange some lines of code and it ran like a charm.

quiz6

Source Code below: [GitHub Link:  https://github.com/diegodamy/Quiz6]

#include <iostream>
using namespace std;

int GetGDC(int numbers[], int size){
int quotient;
int modulus;

do {

if (numbers[0] == 0){
return 1; //cout << “GDC is ” << numbers [1] << endl;
} else if (numbers[1] == 0){
return 0; //cout << “GDC is ” << numbers [0] << endl;
}

quotient = numbers[0]/numbers[1];
modulus = numbers[0]%numbers[1];

numbers [0] = (numbers [1]*quotient)+modulus;

numbers [0] = numbers [1];
numbers [1] = modulus;

} while ((numbers[0] == 0)||(numbers[1] == 0));

}

int main(){
int array [2];

cout << “In order to find the GCD of two numbers, please input two positive integers:” << endl;
for (int i=0; i<2; i++) {
cin >> array[i];
}

if (GetGDC(array,2)==1) {
cout << “The GDC of given numbers is ” << array[1] << endl;
} else if (GetGDC(array,2)==0) {
cout << “The GDC of given numbers is ” << array[0] << endl;
} else {
cout << “The GDC of the given numbers is ” << GetGDC(array,2) << endl;
}
}

———————————————-

QUIZ#6, Euclide algorythm

quiz6
Resumiendo las instrucciones, deberíamos crear un código que recibe dos números o parámetros por parte del usuario, a continuación, en una función se va a imprimir el mayor denominador que divide a ambos números.

quiz6compile

CÓDIGO:

 

#include <iostream>

using namespace std;

 

int euclidianAlgo(int first, int second){

int tem=0;

int res=first%second;

while(res!=0){

first=second;

second=res;

res=first%second; }

 

return second; }

 

 

 

int main() {

int first, second, val;

cout<<“This program does the Euclidian Algorithm of the range of numbers you give”<<endl;

cout<<“Type the lower value”<<endl;

cin>>first;

cout<<“Ok now type the higher value”<<endl;

cin>>second;

val=euclidianAlgo(first, second);

cout<<“The greatest denominator of the two numbers is: “<<” “<<val<<endl; }

Euclids on the block! #Quiz6

Euclides es como mi dignidad, yo aseguro que existe pero nadie está de acuerdo con eso. Al igual que lo anterior dicho, la ente simplemente no puede ponerse de acuerdo sobre si Euclides existió o no, lo que no se puede negar ni de broma, es la utilidad de su algoritmo es la geometría.

Euclid_o_24537

Esta es la mejor imagen que pude encontrar.

El código resultó ser muy sencillo, creo que ha sido el más corto de todos pues la salida del programa sólo tenía que ser el MCD (máximo común divisor) y la función principal era portar el algoritmo de Euclides hacia el lenguaje de programación, el cual resultó en esto:

# --------------------- Este es el código correspondiente al Quiz 6 ----------------------------
def ade(a, b):
if a > b:
c = a - b
ade(b, c)
elif a < b:
c = b - a
ade(a, c)
else:
print(a)

ade(a=int(input("Vamos, introduce el primer número: ")), b=int(input("Ahora introduce el segundo número: ")))

Como siempre, mi código en Github está aquí.