Hi i am new to C++ and want to know how to create an n x n matrix where the numbers go in sequential order in the first row and first column and then continue to increase until n is reached again, whereby the loop starts from 1 again.
e.g. a 5x5 matrix would look like:
to Archaic: I have now ammended it and it should now work, although I am not sure why it wasn't compiling for you.
to Galik: with respect to that line, i have altered that too and this is my new code:
but now i need help making every even number negative.
i.e.
1 -2 3 -4 5
-2 3 -4 5 1
3 -4 5 1 -2
-4 5 1 -2 3
5 1 -2 3 -4
I can get every other element to be negative but the problem arises when you loop around from an odd number back to 1 (i.e. from 5 to1 in this example or 7 to 1 etc.)
Thanks Galik again. Ive created a method that will generate all the factoriadic number upto my inputted value of n. I now want to change this factoriadic number into a permutation. I know the procedure i want to follow, but not sure how i can program it.
I want toiIterate through the factoradic array and create the permutation.
But i am struggling to creat the code and would appreciate the help!!
thanks again!
I'm not an expert on this. I am just going on what Wikipedia says.
From what I understand you need to iterate through your factoradic number array removing one of your values from your input number set each time to build up your permutation.
So it seems to me you could use a std::vector for your factoradic number and another vector containing your input number set:
#include <iostream>
#include <vector>
std::vector<int> fact_to_perm(const std::vector<int>& fact)
{
std::vector<int> perm; // our return permutation
// Initialise our list of all possible values.
std::vector<int> list;
for(size_t i = 0; i < fact.size(); ++i)
{
list.push_back(i);
}
// Then you need to do these things:
// iterate through the factoradic number vector fact
// get current factoradic value
// use that to select a permutation value from the list
// remove that permutation value from the list
// add it to the permutation
}
return perm;
}