Homework assignment help (easy task)

What have you tried so far?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <valarray>
using namespace std;

int maxDiagonal( const valarray<int> &M, int N )
{
   return M[slice(0,N,N+1)].max();
}

int main()
{
   valarray<int> A = { 1,  2,  3,  4,
                       5,  6,  7,  8,
                       9, 10, 11, 12,
                      -1, -2, -3, -4 };
   valarray<int> B = { 10,  25,  6,  2,
                        5,  13,  6,  1,
                       -1,  10,  7,  2,
                        0,   6, 24,  1 };
                      
   cout << maxDiagonal( A, 4 ) << "  " << maxDiagonal( B, 4 ) << '\n';
}


11  13
Last edited on
Topic archived. No new replies allowed.