Hi

I need to do the school homework about group theory, I need generate all permutation array when the user type n ( n is natural number >0). When The user type for example n=4
I fill the first row and first column with the sequence {1,2,3,4}, if he typed n= 5 I fill with {1,2,3,4,5}
Example: for n=4
* | 1 2 3 4
---+----------------------------------------------
1 | 1 2 3 4 -- First row
2 | 2 1 4 3
3 | 3 4 1 2
4 | 4 3 2 1

The number in the top and left are number of columns and rows . Look that First row is 1,2,3,4
and first column is 1,2,3,4
In the second column and row I have generate all
permutation possible, but the number only can to be one time in the column and one time in the row. ( the number 1 only one time in the column 1 , one time in the column 2 ...etc).
Other solution for n=4 is
* | 1 2 3 4
---+----------------------------------------------
1 | 1 2 3 4
2 | 2 3 4 1
3 | 3 4 1 2
4 | 4 1 2 3

do somebody to know the algorithm that generate all
permutation possible without that number show more than one time in the column and row ?
I search abou derangement algorithm but I do not found.
I have to do this program in C or C++ or Pascal or Visual Basic

Thank You in Advance