diff options
author | RossTheRoss <msattr@gmail.com> | 2020-02-09 08:46:52 -0600 |
---|---|---|
committer | RossTheRoss <msattr@gmail.com> | 2020-02-09 08:46:52 -0600 |
commit | bd1d350c376b45e334697851e29b2f79fee0c956 (patch) | |
tree | eb242032a64442caef7a35434400eb0818911e9a /OLD/ee1301/wk5/hw5_directory/strap012_HW5B.cpp | |
parent | Do micro prelab (diff) | |
parent | Rename file (diff) | |
download | homework-bd1d350c376b45e334697851e29b2f79fee0c956.tar homework-bd1d350c376b45e334697851e29b2f79fee0c956.tar.gz homework-bd1d350c376b45e334697851e29b2f79fee0c956.tar.bz2 homework-bd1d350c376b45e334697851e29b2f79fee0c956.tar.lz homework-bd1d350c376b45e334697851e29b2f79fee0c956.tar.xz homework-bd1d350c376b45e334697851e29b2f79fee0c956.tar.zst homework-bd1d350c376b45e334697851e29b2f79fee0c956.zip |
Merge branch 'master' of github.com:RosstheRoss/TestingFun
Diffstat (limited to 'OLD/ee1301/wk5/hw5_directory/strap012_HW5B.cpp')
-rw-r--r-- | OLD/ee1301/wk5/hw5_directory/strap012_HW5B.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/OLD/ee1301/wk5/hw5_directory/strap012_HW5B.cpp b/OLD/ee1301/wk5/hw5_directory/strap012_HW5B.cpp new file mode 100644 index 0000000..f1e0c2c --- /dev/null +++ b/OLD/ee1301/wk5/hw5_directory/strap012_HW5B.cpp @@ -0,0 +1,51 @@ +/*
+Date: April 4 2019
+Name: Matthew Strapp
+Student ID number: 5449340
+Course number: EE 1301
+Term: Spring 2019
+Lab/assignment number: HW 5B
+Short Program Description: Random Array
+*/
+
+#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 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 == 2) { //Decide the sign of the number
+ randArray[curCol][curRow] = -1 * (rand() % (max+1));
+ } else {
+ randArray[curCol][curRow] = (rand() % (max+1));
+ }
+ }
+ }
+
+ //Loop to output the array in the console
+ for (int curRow = 0; curRow < m; curRow++)
+ {
+ for (int curCol = 0; curCol < n; curCol++)
+ {
+ cout << randArray[curCol][curRow] << " ";
+ }
+ cout << endl;
+ }
+}
\ No newline at end of file |