Skip to content

Instantly share code, notes, and snippets.

@alonzoibarra97
Created April 5, 2016 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alonzoibarra97/e1e9c92517741294d582fafffea27862 to your computer and use it in GitHub Desktop.
Save alonzoibarra97/e1e9c92517741294d582fafffea27862 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int gd_c (int a, int b){
int gdc, mod1,div1;
do{
if(a==0)
{
gdc= b;
}
else{
if(b==0)
{
gdc= a;
}
else{
do{
mod1= a%b;
div1= a/b;
a= (b*div1)+mod1;
a=b; b=mod1;
}while(a==0||b==0)
}
}
}while(a==0||b==0);
return gdc;
}
int main () {
int num1,num2,rgdc;
cout<<"Give me the first number\n";
cin>> num1;
cout<<"Give me the second number\n";
cin>> num2;
rgdc= gd_c(num1,num2);
cout<< "The greatest common denominator of these numbers is: "<< rgdc;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment