Answers for "2d vector c++ at"

C++
3

2d vector c++ declaration

vector< vector<int>> a(rows, vector<int> (cols));
Posted by: Guest on January-02-2021
0

2d vector

#include <bits/stdc++.h>
using namespace std;
main() {
	int r=2,c=3,val=1;
	vector<vector<int>> v(r,vector<int>(c,val)); 
	/*
    2d vector “v[r][c]”;
    all elements = val; 
    (default value is 0)
    */
	for(int i=0;i<r;i++) 
		for(int j=0;j<c;j++) 
  			cout<<v[i][j]<<" ";
        cout<<endl;
  	/*
    1 1 1
    1 1 1
    */
}
Posted by: Guest on April-01-2021

Browse Popular Code Answers by Language