小编rrr*_*rrr的帖子

C++最小公约数重写

我创建了一个返回2个数字的最小公约数的函数.

int check (int a, int b)
{
 int i = 2; //every number is divisible by 1
   begin:
    if ((a % i == 0) && (b%i == 0)) //i must be divisible by both numbers
      {
         return i;
      }
    else
      {
          i++;
          goto begin;
      }
}
Run Code Online (Sandbox Code Playgroud)

但是,我正在使用备受建议的反对goto,所以我想知道如何使用forwhile循环重写它.

c++ math

2
推荐指数
1
解决办法
5621
查看次数

标签 统计

c++ ×1

math ×1