Last active
August 29, 2015 14:17
-
-
Save samir96/ac1b460ae54bc0fdce6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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