gpt4 book ai didi

c++ - 比较 4 个变量以找到最低的 C++

转载 作者:可可西里 更新时间:2023-11-01 15:29:40 27 4
gpt4 key购买 nike

我想找到四个中最小的数字,但这看起来有点奇怪,难道没有更聪明、更短的方法吗?

这就是我所拥有的:

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com