View difference between Paste ID: mShn0n4Q and ZzHnZBt9
SHOW: | | - or go back to the newest paste.
1
#include <iostream>
2
#include "matrix.h"
3
using namespace std;
4
 
5
void loadMatrix(mat m, int &r, int &c) {
6
    cout << "Put the number of columns: ";
7
    cin >> c; // columns
8
    cout << "Put the number of rows: ";
9
    cin >> r; // rows
10
 
11
    for (int i = 0; i < r; i++)  // skip to the next row
12
        for (int j = 0; j < c; j++) { // load the elements of the entire line
13
            cout << "Put item (" << i << ", " << j << "): ";
14
            cin >> m[i][j];
15
        }
16
}
17
 
18
void printMatrix(mat m, int r, int c) {
19
    for (int i = 0; i < r; i++) {
20
        for (int j = 0; j < c; j++)
21
            cout << "\t| (" << i << ", " << j << "): " << m[i][j];
22
 
23
        cout << endl;
24
    }
25
}
26
 
27
void sumRows(mat m, int r, int c, vet &vs) {
28
    for (int i = 0; i < r; i++) {
29
        vs[i] = 0;
30
        for (int j = 0; j < c; j++)
31
            vs[i] += m[i][j];
32
    }
33
}
34
 
35
// sums the elements between the two diagonals
36
int sumIncluded(mat m, int r, int c) {
37
    int s = 0;
38
    for (int i = 0; i < (r / 2); i++)
39-
        for (int j = i; j < c - i; j++) {
39+
        for (int j = i; j < c - i; j++)
40-
            cout << "m[" << i << ", " << j << "]: " << m[i][j]
40+
41-
                 << " m[" << (r-1)-i << ", " << j << "]: " << m[(r-1)-i][j] << endl;
41+
42
    if ((r % 2) == 0)
43
        return s;
44
    else
45
        return s + m[(r-1)/2][(r-1)/2];
46
}
47
48