【发布时间】:2021-07-02 22:34:03
【问题描述】:
我的代码的问题是它没有识别我的函数,我不确定函数是否不正确或使用错误的语法编写。我尝试的是为最大索引的位置创建一个新数组,但它似乎不起作用。
#include <iostream>
#include <iomanip>
using namespace std;
void locateLargest(const double a[][4], int location[]);
const int ROW_SIZE = 3;
const int COLUMN_SIZE = 4;
int main(){
int location [ROW_SIZE][COLUMN_SIZE];
double matrix [ROW_SIZE][COLUMN_SIZE];
double input;
cout<<"Enter the array: "<< endl;
for (int i = 0; i < ROW_SIZE; i++){
for(int j = 0; j < COLUMN_SIZE; j++){
cin>>input;
matrix[i][j] = input;
}
}
for(int i = 0; i < ROW_SIZE; i++){
for(int j = 0; j < COLUMN_SIZE; j++){
cout<< setw(4)<<matrix[i][j]<< " ";
}
cout<< endl;
}
locateLargest(matrix, location)
}
【问题讨论】:
-
为什么要为行+列对返回一个 3x4 矩阵?
-
为什么要把所有元素都和
a[0][0]比较?您应该将所有元素与当前最大值进行比较。location应该包含位置而不是值。你需要类似 `if(a[location[0]][location[1]] -
你不是说位置是
int location[2]吗? -
你有一个名为
locateLargest的函数。您可能想回答这些问题。您希望它返回该位置还是打印该位置?如果要返回位置,是位置(您如何表示它)?
标签: c++ arrays function loops matrix