Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "matrix.h"
- using namespace std;
- void loadMatrix(mat m, int &r, int &c) {
- cout << "Put the number of columns: ";
- cin >> c; // columns
- cout << "Put the number of rows: ";
- cin >> r; // rows
- for (int i = 0; i < r; i++) // skip to the next row
- for (int j = 0; j < c; j++) { // load the elements of the entire line
- cout << "Put item (" << i << ", " << j << "): ";
- cin >> m[i][j];
- }
- }
- void printMatrix(mat m, int r, int c) {
- for (int i = 0; i < r; i++) {
- for (int j = 0; j < c; j++)
- cout << "\t| (" << i << ", " << j << "): " << m[i][j];
- cout << endl;
- }
- }
- void sumRows(mat m, int r, int c, vet &vs) {
- for (int i = 0; i < r; i++) {
- vs[i] = 0;
- for (int j = 0; j < c; j++)
- vs[i] += m[i][j];
- }
- }
- // sums the elements between the two diagonals
- int sumIncluded(mat m, int r, int c) {
- int s = 0;
- for (int i = 0; i < (r / 2); i++)
- for (int j = i; j < c - i; j++)
- s += m[i][j] + m[(r-1)-i][j];
- if ((r % 2) == 0)
- return s;
- else
- return s + m[(r-1)/2][(r-1)/2];
- }
Advertisement
Add Comment
Please, Sign In to add comment