size of a matrix using vector c++
// finding size of a square matrix
myVector[0].size();
size of a matrix using vector c++
// finding size of a square matrix
myVector[0].size();
c++ 2D vectors
int main()
{
int row = 5; // size of row
int colom[] = { 5, 3, 4, 2, 1 };
vector<vector<int> > vec(row); // Create a vector of vector with size equal to row.
for (int i = 0; i < row; i++) {
int col;
col = colom[i];
vec[i] = vector<int>(col); //Assigning the coloumn size of vector
for (int j = 0; j < col; j++)
vec[i][j] = j + 1;
}
for (int i = 0; i < row; i++) {
for (int j = 0; j < vec[i].size(); j++)
cout << vec[i][j] << " ";
cout << endl;
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us