-
Notifications
You must be signed in to change notification settings - Fork 361
/
Copy pathnofunction.cpp
53 lines (38 loc) · 1.06 KB
/
nofunction.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <float.h>
struct Matrix
{
size_t rows;
size_t cols;
float * pData;
};
int main()
{
using namespace std;
Matrix matA = {3,4};
matA.pData = new float[matA.rows * matA.cols]{1.f, 2.f, 3.f};
Matrix matB = {4,8};
matB.pData = new float[matB.rows * matB.cols]{10.f, 20.f, 30.f};
Matrix matC = {4, 2};
matC.pData = new float[matC.rows * matC.cols]{100.f, 200.f, 300.f};
// some operations on the matrices
float maxa = FLT_MIN;
float maxb = FLT_MIN;
float maxc = FLT_MIN;
//find max value of matA
for(size_t r = 0; r < matA.rows; r++)
for (size_t c = 0; c < matA.cols; c++)
{
float val = matA.pData[ r * matA.cols + c];
maxa = ( maxa > val ? maxa : val);
}
//find max value of matB
//find max value of matC
cout << "max(matA) = " << maxa << endl;
cout << "max(matB) = " << maxb << endl;
cout << "max(matC) = " << maxc << endl;
delete [] matA.pData;
delete [] matB.pData;
delete [] matC.pData;
return 0;
}