Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int gcd1(int m, int n)
- {
- for (int div = m > n ? n : m; div >= 1; div--) {
- if (m % div == 0 && n % div == 0) {
- return div;
- }
- }
- return 0;
- }
- int gcd2(int m, int n)
- {
- if (n == 0) {
- return m;
- } else {
- return gcd2(n, m % n);
- }
- }
- int main()
- {
- int m = 18;
- int n = 12;
- cout << m << " " << n << " " << gcd1(m, n) << " " << gcd2(m, n) << endl;
- m = 17, n = 18;
- cout << m << " " << n << " " << gcd1(m, n) << " " << gcd2(m, n) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement