Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

不使用除号实现整数相除 #995

Open
pwstrick opened this issue Jul 6, 2020 · 0 comments
Open

不使用除号实现整数相除 #995

pwstrick opened this issue Jul 6, 2020 · 0 comments
Labels
一句话算法 一句话算法系列中的代码实现

Comments

@pwstrick
Copy link
Owner

pwstrick commented Jul 6, 2020

/*
 ** 函数功能: 计算两个自然数的除法
** 输入参数: m 为被除数,n 为除数
 ** 返回值: res 为商,remain 为余数
 */
function devide1(m, n) {
  var res = 0,
    remain = m;
  //被除数减除数,直到相减结果小于除数为止
  while (m > n) {
    m = m - n;
    res += 1;
  }
  remain = m;
  return { 
    res: res, 
    remain: remain
  };
}
@pwstrick pwstrick added the 一句话算法 一句话算法系列中的代码实现 label Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
一句话算法 一句话算法系列中的代码实现
Projects
None yet
Development

No branches or pull requests

1 participant