QUIZ 6

Este programa escribe una función para calcular el máximo común denominador de dos números positivos;

//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-05-14 a las 11.19.21.png

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