[ create a new paste ] login | about

Link: http://codepad.org/4IaYF0de    [ raw code | output | fork ]

C++, pasted on Oct 22:
#include <iostream>
#include <ctime> 
 
using std::cout;
using std::cin;
using std::endl;
 
int main()
{    
         srand((unsigned)time(NULL)); 
         int m,n,max_rows,max_cols,min_rows,min_cols;
         int **mat;
         //cout<<"Enter m: ";
         //cin>>m; 
           m=4;
          cout<<endl;
        // cout<<"Enter n: ";
         //cin>>n;
          n=5;
     mat = new int*[m];
          for(int i=0; i<m; i++)
           {
                   mat[i] = new int[n];
                     for(int j=0; j<n; j++)
                          {
                 mat[i][j]=rand()%7;
                                 cout<<mat[i][j]<<"  ";
                          }
           cout<<endl;
           }
          max_cols=mat[0][0];
      min_cols=mat[0][n-1];
          max_rows=mat[1][1];
          min_rows=mat[1][n-2];
          for(int i=0; i<m; i++)
           {
                       if(mat[i][0]>max_cols)
                            {
                                   max_cols = mat[i][0];
                            }
                           if(mat[i][n-1]<min_cols)
                            {
                                   min_cols = mat[i][n-1];
                            }
                   }
          for(int i=1; i<n; i++)
            {
               if(mat[1][i]>max_rows)
                            {
                   max_rows = mat[1][i];
                            }
                           if (mat[m-2][i]<min_rows)
                            {
                   min_rows = mat[m-2][i];
                            }
                }
           cout<<"Max_cols_1 -> "<<max_cols<<endl;
           cout<<"Min_cols_"<<n<<" -> "<<min_cols<<endl;
           cout<<"Max_rows_2 -> "<<max_rows<<endl;
           cout<<"Min_rows_"<<m-1<<" -> "<<min_rows<<endl;
 
          for(int i=0; i<m; i++)
                  delete mat[i];
                delete [] mat;
     system("pause");
     return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11

4  2  1  4  6  
0  5  3  1  3  
4  1  3  5  0  
0  2  0  0  6  
Max_cols_1 -> 4
Min_cols_5 -> 0
Max_rows_2 -> 5
Min_rows_3 -> 0

Disallowed system call: SYS_fork


Create a new paste based on this one


Comments: