[ create a new paste ] login | about

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

C++, pasted on Feb 8:
#include <iostream>
using namespace std;

int main()
{
	srand(time(0));
	int n = 0;
	//cin >> n;
        cout<<"n = "<<(n = 8)<<endl;
        int **a = new int* [n];
	int imax = 0;
	int jmax = 0;
	for (int i = 0; i < n; i++)
	{
	     a[i] = new int [n];
 	     for (int j = 0; j < n; j++)
 	     {
  	          a[i][j] = rand() % 100;
  	          cout << a[i][j] << " ";
  	          if(a[imax][jmax] < a[i][j])
   	          {
   	              imax = i;
   	              jmax = j;
   	          }
             }
   	 }
         cout<<"\nmaxElement : "<<a[imax][jmax]<<endl;
         cout<<"\nmaxElement : "<<*std::max_element(a, a + n)<<endl;
         return 0;
}


Output:
1
2
3
4
5
n = 8
63 7 54 79 57 93 20 72 15 23 71 58 18 24 28 39 13 91 28 7 45 29 31 85 36 62 64 21 24 98 87 39 58 42 70 15 35 91 39 2 14 62 61 84 86 89 23 51 80 52 58 77 33 42 63 22 56 79 43 80 30 30 71 88 
maxElement : 98

maxElement : 0x8051740


Create a new paste based on this one


Comments: