blob: 4576e5975eb050a574fbdf5306a400eb369538af (
plain) (
blame)
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
|
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[])
{
if (argc != 4) {
cout << "Invalid input!" << endl << " USAGE: ./rand-array m n max" << endl;
return 2;
}
srand(time(NULL));
int m, n, max;
m = atoi(argv[1]); //number of rows
n = atoi(argv[2]); //number of columns
int randArray[m][n];
max = atoi(argv[3]); //Maximum number
for (int curRow = 0; curRow < m; curRow++)
{
for (int curCol = 0; curCol < n; curCol++)
{
if (rand() % 2 == 1) {
randArray[curRow][curCol] = -1 * (rand() % max);
} else {
randArray[curRow][curCol] = (rand() % max);
}
}
}
cout << endl;
}
|