【发布时间】:2019-01-26 20:49:40
【问题描述】:
我是新来的。 我开始学习编程和C++。 我必须做一个程序,向用户请求数字来填充一个数组,然后是一个函数来查找最高和最低值及其在数组中的位置。 这就是我现在所拥有的,它可以找到最高的数字及其位置,但它不能找到最低的,找到的最低值不正确,或者它的位置:
int main() {
int array[SIZEF][SIZEC];
int zero = 0;
int highest[0][0]; //to find the highest, array from 0 value.
int lowest[0][0]; //to find the lowest, takes the highest value and then compare, if its lower than the current value of the array, it takes its value
highest[0][0] = zero;
fill_array(array, SIZEF, SIZEC);
highlow(array, SIZEF, SIZEC, highest, lowest);
getchar();
return 0;
}
void fill_array(int array[][SIZEC], int sizef, int sizec) {
//code to fill the array, no problem here.
}
void highlow(int array[][SIZEC], int sizef, int sizec, int highest[][0], int lowest[][0]) {
int positionX = 0;
int positionY = 0;
for (int i = 0; i < sizef; i++) {
for (int j = 0; j < sizec; j++) {
if (array[i][j] > highest[0][0]) {
//if the current value of the array is higher than highest value, highest value takes its value.
highest[0][0] = array[i][j];
positionX = i;
positionY = j;
lowest[0][0] == highest[0][0]; //now lowest value its the highest value
if (array[i][j] < lowest[i][j]) { //so, if current array value its lower than lowest value
//lowest value takes its value.
lowest[0][0] = array[i][j];
}
}
}
}
}
非常感谢。 (对不起我的英语,我也在学习)。
【问题讨论】:
-
Plàcid Masvidal,您使用的编译器和设置没有警告
int highest[0][0];?
标签: c arrays multidimensional-array