-2

I have to code a program using C++ at university.

They asked me to type all elements of a 3x3 matrix. And all elements have to be positive. So far so good. Each row of the matrix represents the components of a R^3 vector. So there are three vectors (Three 1D arrays). I had to calculate the modulus of each vector and successfully did it.

Here comes the problem... The next step is to get which vector the largest modulus has, and return its position. All this using a function --> int largestModulus (int Modulus[3]). How can I do that? Because it is all about comparing but this time is comparing a vector, and I only know how to compare different single elements. Thanks for your help!!

  • Assuming that by "vector" you mean an `std::vector` or an `std::array` you can just use `operator ==` and it will work as expected. If you have C arrays you should not use those. If you must use C arrays just compare every number individually. [`std::tie` can help](https://stackoverflow.com/q/6218812/3484570). – nwp Nov 07 '17 at 16:28
  • Welcome to Stack Overflow! Please refer to the [How to ask](https://stackoverflow.com/help/how-to-ask) page to formulate a good question. Coming to the matter at hand: you are requested to compare the modulo, which is a number, not the vector. – Pietro Saccardi Nov 07 '17 at 16:30

1 Answers1

0

In the arguments to the function, since you're passing and receiving a 2D matrix, the parameter must be

int largestModulus (int Modulus[][3])
Frank
  • 9
  • 3
  • It seems like `int largestModulus (int Modulus[3])` is given by the assignment and cannot be changed. – nwp Nov 07 '17 at 16:31