Skip to content

Instantly share code, notes, and snippets.

@pif
Created April 3, 2011 21:18
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 pif/900825 to your computer and use it in GitHub Desktop.
Save pif/900825 to your computer and use it in GitHub Desktop.
gcd: while/recursion
#include <iostream>
using namespace std;
int gcd(int a,int b) {
if (!b) {
return a;
}
cout<<a<<"="<<b<<"*"<<a/b<<"+"<<a%b<<endl;
return gcd(b, a%b);
}
/* int r = 0;
while(b!=0) {
r = a%b;
a = b;
b = r;
cout<<a<<" ololo "<<b<<endl;
}
return r;
}*/
int main() {
int a = 211;
int b = 79;
cout<<"GCD: "<<gcd(a,b)<<endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment