除了一个小问题之外,这段代码对我来说工作得很好。在调用 myfind_min和find_max函数之后,代码还打印出一个看似随机的数字。我认为这与引用传递有关,它是一个内存值或其他东西。有人可以解释并告诉我如何摆脱它吗?谢谢。
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
using namespace std;
//get_avg function will get the average of all temperatures in the array by using for loop to add the numbers
double get_avg(int* arr, int n) {
double res = 0.0;
for(int i = 0; i<n; i++){
res += arr[i];
}
return (res/n); //average
}
void get_array(int* arr){
int i;
for(i=0; i<25; i++){
arr[i] = (rand() % 100) + 1;
}
}
//prints the …Run Code Online (Sandbox Code Playgroud)