Guest

Write a program in C++ to display a matrix in ascending order

Write a program in C++ to display a matrix in ascending order

Grade:10

1 Answers

SAGAR SINGH - IIT DELHI
878 Points
13 years ago

Dear student,

#include  <iostream>

using namespace std;

#define  m  3

#define  n  3

 

int main()

{

     int  i, j;

     int  x[m][n]={{10,25,33}, {21,32,43},{20,42,51}};

     cout<<"\n3x3 arrays' subscripts and\n";

     cout<<"their respective elements\n";

     cout<<"--------------------------\n";

     // the outer for loop, reading the row by row...

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

            // the inner loop, for every row, read every column by column...

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

                  cout<<"["<<i<<"]"<<"["<<j<<"]"<<"="<<x[i][j]<<"\n";

     return 0;

}

 

Think You Can Provide A Better Answer ?

ASK QUESTION

Get your questions answered by the expert for free