when i run it it reads the abort line.

//Nicholas El Habr
//201800512
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char** argv) {
if (argc != 3) {
cout << "You have supplied an invalid number of command line arguments. Aborting." << endl;
return 1;
} else {
int m = atoi(argv[1]);
int n = atoi(argv[2]);
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++)
cout << i + m * j << " ";
cout << endl;
}
}
}

//Write a program grid.cpp that accepts two command line arguments m,n as integers and prints an m x n grid of numbers in column major order where each cell’s value is i+mj.

//>5 6

0 5 10 15 20 25
1 6 11 16 21 26
2 7 12 17 22 27
3 8 13 18 23 28
4 9 14 19 24 29
Are you aware of how to pass command-line arguments?

Open the directory where your program is in your terminal or cmd, and then do
program.exe 5 6
.

./program 5 6 if linux.
Last edited on
Topic archived. No new replies allowed.