Skip to content

Instantly share code, notes, and snippets.

@samir96
Last active August 29, 2015 14:17
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 samir96/ac1b460ae54bc0fdce6e to your computer and use it in GitHub Desktop.
Save samir96/ac1b460ae54bc0fdce6e to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int gcd(int a, int b) {
if(a == 0 ) return b;
if(b == 0 ) return a;
if(a > b) return gcd(b,a%b);
if(b>a) return gcd(a,b%a);
}
int main(){
int n1, n2;
cout << "Give me a number, please: ";
cin >> n1;
cout << "Give me another number: ";
cin >> n2;
cout << "The gcd of " << n1 << " and " << n2 << " is " << gcd(n1, n2) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment