iterative greatest common divisor gcd

Solutions on MaxInterview for iterative greatest common divisor gcd by the best coders in the world

showing results for - "iterative greatest common divisor gcd"
Laura
23 Aug 2017
1#include <iostream>
2
3using namespace std;
4
5long long gcd(long long m, long long n) {
6  while ( m != 0)  {
7    long long old_m = m;
8    m = n % m;
9    n = old_m;
10  }
11  return abs(n);
12}
13 
14int main() {
15    cout << gcd(2672, 5678) << endl;  
16}
similar questions
queries leading to this page
iterative greatest common divisor gcd