Calculator  Step 6
gcd.hpp
Go to the documentation of this file.
1 #ifndef GCD_HPP_
2 #define GCD_HPP_
3 
7 template<class T>
8 T gcd(T n, T m)
9 {
10  static T zero{};
11  if (n < zero)
12  n = -n;
13  while (m != zero) {
14  int tmp(n % m);
15  n = m;
16  m = tmp;
17  }
18  return n;
19 }
20 #endif
T gcd(T n, T m)
Definition: gcd.hpp:8