• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Mar 31st, 2020 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include "MatrixVec.h"
2. #include <cstdlib>
3. #include <iostream>
4.
5. using namespace std;
6.
7. MatrixVec::MatrixVec(int rows, int cols, int range)
8. {
10.     // Zauzeti memoriju za matricu dimenzija rows*cols
11.     matrixVector.resize(rows);
12.     for (int i = 0;i < rows;i++) {
13.         matrixVector[i].resize(cols);
14.     }
15.
16.     // Matricu inicijalizovati nasumičnim vrednostima u opsegu [0, range)
17.     for (int i = 0;i < rows;i++) {
18.         for (int j = 0;j < cols;j++) {
19.             matrixVector[i][j] = rand() % range + 1;
20.         }
21.     }
22. }
23.
24. void MatrixVec::print()
25. {
27.     // Odštampati sadržaj matrice na ekran
28.     for (int i = 0;i < matrixVector.size();i++) {
29.         for (int j = 0;j < matrixVector[i].size();j++) {
30.             cout << matrixVector[i][j] << "\t";
31.
32.         }
33.         cout << endl;
34.     }
35.
36. }
37.
38. void MatrixVec::process()
39. {
42.
43.     int broj = 0;
44.     for (int j = 0;j < matrixVector[0].size();j++) {
45.         for (int i = 0;i < matrixVector.size();i++) {
46.             if (matrixVector[i][j] % 2 != 0) {
47.                 broj++;
48.             }
49.         }
50.         cout << "Broj neparnih clanova u koloni" << j+1 << "je:" << broj<<endl;
51.         broj = 0;
52.     }
53.
54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top