代码改变世界

一些常用的基础函数实现

2015-06-09 22:35  sylar_liang  阅读(140)  评论(0编辑  收藏  举报

1.求公约数

// return the greatest common divisor
int gcd(int v1, int v2)
{
  while(v2)
  {
    int temp = v2;
    v2 = v1%v2;
    v1 = temp;
  }
  return v1;
}

 

2.