Computer Science, asked by jeevankumarbura, 1 day ago

Single File Programming Question Preethi is in the middle of a contest and she is not able to crack a problem. So please help her to find the solution to her problem. Given a matrix of size M*N, write a program to find its submatrix obtained by deleting the specified row and column.​

Answers

Answered by pruthaasl
0

Answer:

#include <iostream>

#include <iomanip>

using namespace std;

#define MAX 10

int main() {

   int a[MAX][MAX];

   int i, j, n, m, r, c;

   cout<<"\nEnter number of rows and columns: ";

   cin>>m>>n;

   cout<<"\nEnter the elements: ";

   for(i=0;i<m;i++)

   {

       for(j=0;j<n;j++)

       cin>>a[i][j];

   }

   cout<<setw(5)<<endl;

   for(i=0;i<m;i++)

   {

       for(j=0;j<n;j++)

       {

       cout<<a[i][j];

       }

       cout<<endl;

   }

   cout<<"\nEnter the number of row and column to be deleted: ";

   cin>>r>>c;

   for(i=0;i<m&&i!=r;i++)

   {

       for(j=0;j<n&&j!=c;j++)

       {

           cout<<a[i][j];

       }

       cout<<endl;

   }

   return 0;

}

Explanation:

  • We start by declaring a two-dimensional array and the necessary variables to store the data.
  • Take the number of rows, columns, and matrix elements as the input from the user and store them.
  • Display the matrix using nested for loops.
  • Take the number of rows and columns to be deleted from the user and store them.
  • To delete the specified row and column, we modify the expression in the for loops.
  • The elements of the specified row and column are ignored and the rest of the elements are printed.

#SPJ3

Similar questions