hello, dear all. below is my program code. the problem is an half of my output is zero for entries of matrix for n greater than 4.
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#define MAX 100
int num[MAX][MAX];
int n;
int nrows = 0;
using namespace std;
void print(int i )
{
if (i > 0) {
for (int j = 1; j <=n; j++)
//cout << num[i][j];
cout << "num["<<i<<"]["<<j<<"]=" <<num[i][j] << endl;
cout <<"\n";
}
}
void rightRotate ( int n)
{int tmp;
for(int k = 1; k<n; ++k)
for(int l = 1; l<=n; ++l)
{
//cout << "l:"<< l << "\n";
tmp = num[l][k];
num[l][k]= num[l][k+1];
num[l][k+1] = tmp;}
}
void matrixPermute (int n)
{
int i, temp;
if (n ==3 )
{nrows ++;
print(nrows);
return;
}
temp = n-1 ;
cout << "temp:"<< temp<<"\n";
for (i = 1; i <=temp ; ++i)
{
//cout << "i:" << i << "\n";
matrixPermute (temp);
rightRotate (temp);
}
}
void initiate(int n)
{
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
{
num[i][j] = j;
}
}
int main ()
{
cout << "number must be between 3 and 10 \n";
cin >> n;
cout << endl;
initiate(n);
matrixPermute (n);
cout << "nrows=" <<nrows << "\n";
}
its cant read the following code that i set it up
void matrixPermute (int n)
{
int i, temp;
if (n ==3 )
{nrows ++;
print(nrows);
return;
}