相关疑难解决方法(0)

找到C++中3个数字中最小的数字

有没有办法让这个功能更优雅?我是C++的新手,我不知道是否有更标准化的方法来做到这一点.这可以变成一个循环,所以变量的数量不受我的代码限制吗?

float smallest(int x, int y, int z) {

  int smallest = 99999;

  if (x < smallest)
    smallest=x;
  if (y < smallest)
    smallest=y;
  if(z < smallest)
    smallest=z;

  return smallest;
}
Run Code Online (Sandbox Code Playgroud)

c++ max min

28
推荐指数
6
解决办法
8万
查看次数

标签 统计

c++ ×1

max ×1

min ×1