Question: in C++ is this how I declare the 2d dynamic vector? vector>matrix; how do i populate the vector ,print it , find the rows and
in C++
is this how I declare the 2d dynamic vector?
vector>matrix;
how do i populate the vector ,print it , find the rows and print the major diagnols with 1s
program prompts the user to enter the length if a square matrix, randomly fill in 0s and 1s into the matrix , print the matrix, and find the rows and major diagonal with all 1s
This is what i have so fare but it dosnet track the rows full of 1s or major diagnols with 1s
#include
#include
#include
using namespace std;
int main()
{
srand(time(0)); //this is for random generation
vector
int m=0;
cout << " Please enter size of matrix : ";
cin>> m;
//adding elements to 2D vector
for(int i=0; i { vector for(int j=0; j // this will full in random values of 0 and 1 row.push_back(rand()%2); // you can fill in the values here matrix.push_back(row); } //printing the vector for(int i=0; i { for(int j=0; j cout< cout< } // this will print the diagonal elements from left to right cout<<"All Rows with 1s, and major diagnols with 1s"; for(int i=0; i { for(int j=0; j { if(i==j) cout<<" :"< } } cout << endl; return 0; } in C++
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
