-
Notifications
You must be signed in to change notification settings - Fork 0
/
random_matrix_gen
67 lines (49 loc) · 995 Bytes
/
random_matrix_gen
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int dim;
int cMatrix;
int genMatrix(cMatrix)
{
int nrow = 0,ncol = 0, i = 0,j = 0;
nrow = dim;
ncol = dim;
srand(time(0));
for (i=0; i < nrow; i++)
{
for (j=0; j < ncol; j++)
{
if (i==j)
{
cMatrix[i][j] = 0;
}
else
cMatrix[i][j] = rand() % 11; // nums generated between 0 - 10
}
}
}
}
int printMatrix(cMatrix[][]){
int nrow = 0,ncol = 0, i = 0,j = 0;
nrow = dim;
ncol = dim;
for (int i=0; i < nrow; i++)
{
for (int j=0; j<ncol; j++)
{
cout << cMatrix [i][j] << " " ;
}
cout<<endl;
}
}
int main()
{
cout << "Give me the number of nodes: " << endl;
cin >> dim;
cout << "There are " << dim << " nodes and the generated matrix looks like this: "<<endl;
int cMatrix[dim][dim];
genMatrix();
printMatrix();
return 0;
}