我想找到四个中最小的数字,但这看起来有点奇怪,难道没有更聪明、更短的方法吗?
这就是我所拥有的:
int findlowest(int one, int two, int three, int four) {
int output = one //as of now , we will be outputting one , except if we find a lower score.
if(output > two) { out = two;} // if output is proven to be bigger than two, two is our new output.
if(output > three){ output = three;} //same operation with three
if(output > four){ output = four;} // same operation with four
return output;
}
最佳答案
std::min(a, std::min(b, std::min(c, d)));
包括<algorithm>
.
关于c++ - 比较 4 个变量以找到最低的 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6578841/