Question & Answer: Writing a program that if an element in an m*n matrix is 0, it's entire row and column is set to 0……

Writing a program that if an element in an m*n matrix is 0, it’s entire row and column is set to 0.

The user must enter the number of rows, columns and contents of the array.
The code attached doesn’t work but the code in the comments works which has a manually entered matrix. I need a user input matrix
Vodacom令 1:43 PM Done 1 of 2 #include <iostream> #include <memory.h> #include <cstdlib? using namespace std; void SetZeros (int** matrix, int m, int n) int row[m]; int column [n] //store the row and column index for (int i-0; i<m; i++) for (int j-0; j<n; j++) if (*((int*) matrix +n* i + row [i] = 1; column [j] -1; //set arr [i][j] to 0 if either row i or column j has a 0 in it: for (int i-0; i<m; i++) for (int j 0; j<n; j++) if (row[i] -1 Il column [j] *((int*) matrix+ n *i +
media%2Ffd9%2Ffd989c0a-9978-4c5f-9d8a-49
media%2F81a%2F81a8b30a-93e1-4820-94d9-67

Vodacom令 1:43 PM Done 1 of 2 #include #include #include

Expert Answer

 

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: Writing a program that if an element in an m*n matrix is 0, it's entire row and column is set to 0……
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

#include<iostream>
#include<memory.h>
#include<cstdlib>
using namespace std;

void SetZeros(int** matrix,int m,int n)
{
int row[m];
int column[n];
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(*((int*)matrix+n*i+j)==0)
{
row[i]=1;
column[j]=1;
}
}
}
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(row[i]==1 || column[j]==1)
{
*((int*)matrix+n*i+j)=0;
}
}
}
}

void fillArray(int** matrix,int m,int n)
{
cout<<“Enter Data in Array “<<endl;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cout<<“Enter element [“<<i<<“][“<<j<<“]: “<<endl;
cin>>*((int*)matrix+n*i+j);
}
}
}

void printArray(int** matrix,int m,int n)
{
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cout<<*((int*)matrix+n*i+j)<<” “;
}
cout<<endl;
}
}

int main()
{
int m;
int n;
cout<<“please enter number of rows: “<<endl;
cin>>m;
cout<<“Please enter the number of columns: “<<endl;
cin>>n;
int matrix[m][n];
fillArray((int**)matrix,m,n);
cout<<“nEntered Matrix is: “<<endl;
printArray((int**)matrix,m,n);

SetZeros((int**)matrix,m,n);
cout<<“The answer is: “<<endl;
printArray((int**)matrix,m,n);
return 0;
}

Question & Answer: Writing a program that if an element in an m*n matrix is 0, it's entire row and column is set to 0...... 1

Still stressed from student homework?
Get quality assistance from academic writers!