Average of 2d array
I need to create an average of rows and columns of a 2d array with random numbers. I have created the nested for loop, but the output is 3 numbers like this -2.345e^4321(not the exact output, but the range is 0 -100 integers, so a double average shouldn't get this output. I apologize, I was in another class. Here's code, even though I did work on it a bit, but now I get the averages in the range, but now I don't have random numbers: #include <iostream> #include <ctime> #include <cstdlib> using namespace std; int main() { srand(time(NULL)); const int rows =3; const int cols =3; int ranInt[rows][cols]; int sum = 0; double average =0; for(int row = 0; row < rows; row++){ for(int col =0; col < cols; col++){ sum+= ranInt[rows][cols]; // cout << sum; } double average = sum/(cols*rows); cout << "Average: " << average<<endl; } return 0; }