Input elements in an array

How do I prompt a user to input the elements in a 10x10 array?

So far, this is what I have:

#include <iostream>
using namespace std;
int main()
{
int N = 0;
cout << "Please enter what the dimensions are for the matrix: ";
cin >> N;
while(N<2 && N>10)
{
cout << "Please re-enter N: ";
}
int matrix[N][N]


Not sure where to go from here. Eventually, I will have to sum the major diagonal, but that part is easy.
Last edited on
closed account (48T7M4Gy)
How do I prompt a user to input the elements in a 10x10 array?

Don't you need to declare the 10x10 array first?

cout << "Please enter what the dimensions are for the matrix: ";

This is not consistent with the 10x10 array idea?
I will assume he meant an nxn array.
You will need a nested for loop to traverse the whole array inside the second for loop you might ask the user what they want the value to be, going through the whole array.

If you meant 10x10 then the for loops will have for(int i = 0; n<10;i++)
Topic archived. No new replies allowed.