Quiz 6

Write a function to calculate the greatest common denominator of two positive integers using Euclid’s algorithm.

//CODE:

#include <iostream>
using namespace std;

int gcd(int x, int y){
int r;
if (x==0){
return x;
}
while (y!=0){
r= y;
y= x%y;
x= r;
}
return r;
}

int main (){
int x,y;
cout<<“Please enter a number: ” <<endl;
cin>>x;
cout<<“Please enter a second number: ” <<endl;
cin>>y;
cout<<“The greatest common denominator between (” <<x <<” y ” <<y <<“) is = ” << gcd(x,y) <<endl;

return 0;
}

Captura de pantalla 2016-04-30 a las 21.54.25.png

Captura de pantalla 2016-04-30 a las 21.56.18

CC BY-SA 4.0 Quiz 6 by everolivares is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.