aboutsummaryrefslogtreecommitdiffstats
path: root/ee1301/wk5
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ee1301/wk5/hw5_directory/strap012_HW5B.cpp25
-rw-r--r--ee1301/wk5/hw5_directory/strap012_HW5C.cpp11
2 files changed, 29 insertions, 7 deletions
diff --git a/ee1301/wk5/hw5_directory/strap012_HW5B.cpp b/ee1301/wk5/hw5_directory/strap012_HW5B.cpp
index 4576e59..ca6d150 100644
--- a/ee1301/wk5/hw5_directory/strap012_HW5B.cpp
+++ b/ee1301/wk5/hw5_directory/strap012_HW5B.cpp
@@ -8,23 +8,34 @@ int main(int argc, char *argv[])
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
+ max = atoi(argv[3]); //Maximum number in array
+
+ //Loop to make the random array
for (int curRow = 0; curRow < m; curRow++)
{
for (int curCol = 0; curCol < n; curCol++)
- {
- if (rand() % 2 == 1) {
- randArray[curRow][curCol] = -1 * (rand() % max);
+ {
+ if (rand() % 2 + 1 == 2) { //Decide the sign of the number
+ randArray[curRow][curCol] = -1 * (rand() % (max+1));
} else {
- randArray[curRow][curCol] = (rand() % max);
+ randArray[curRow][curCol] = (rand() % (max+1));
}
}
}
-
- cout << endl;
+
+ //Loop to output the array in the console
+ for (int curRow = 0; curRow < m; curRow++)
+ {
+ for (int curCol = 0; curCol < n; curCol++)
+ {
+ cout << randArray[curRow][curCol] << " ";
+ }
+ cout << endl;
+ }
} \ No newline at end of file
diff --git a/ee1301/wk5/hw5_directory/strap012_HW5C.cpp b/ee1301/wk5/hw5_directory/strap012_HW5C.cpp
new file mode 100644
index 0000000..9948820
--- /dev/null
+++ b/ee1301/wk5/hw5_directory/strap012_HW5C.cpp
@@ -0,0 +1,11 @@
+#include <iostream>
+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;
+ // }
+
+} \ No newline at end of file