返回传入int数组中的最小值,求空白处代码
#include <iostream>using namespace std;
int min(const int* numbers, int cnt)
{
int res =__________;
for(__________ ; i<cnt ; i++)
{
if( __________)
res = numbers;
}
return res;
}
int main()
{
int nums[] = {8, 12, 23, 4, 11};
cout << min(nums, 5) <<endl;//输出:4
return 0;
}
#include <iostream>
using namespace std;
int min(const int* numbers, int cnt)
{
int res =numbers;//将数组第一个数假定为最小值
for( int i = 0 ; i<cnt ; i++)
{
if(res>numbers)//出现比假定最小值还小的数就将更小的值赋给变量 res
res = numbers;
}
return res;
}
int main()
{
int nums[] = {8, 12, 23, 4, 11};
cout << min(nums, 5) <<endl;//输出:4
return 0;
} #include <iostream>
using namespace std;
int min(const int* numbers, int cnt)
{
int res =numbers;
for( int i = 1 ; i<cnt ; i++)
{
if( numbers<numbers)
res = numbers;
}
return res;
}
int main()
{
int nums[] = {8, 12, 23, 4, 11};
cout << min(nums, 5) <<endl;//输出:4
return 0;
}
页:
[1]