I want a 3x3 matrix with digits 1 to 9 without any digits being repeated.
So i coded as follows(using Borland 5.5 Compiler) :-
#include <iostream.h>
#include <stdlib.h>
#include <dos.h>
#include <conio.h>
int mat[9]={1,2,3,4,5,6,7,8,9};
int nmat[3][3];
void main()
{
randomize();
int k,l,ctr=0,ctr1=0;
int i,j;
while(ctr<=7)
{
for(i=ctr;i<3;i++)
{
for(j=ctr1;j<3;j++)
{
nmat[i][j]=mat[k=random(9)];
for(l=k;l<8;l++)
{
mat[l]=mat[l+1];
}
//ctr1++;
}
//ctr++;
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<nmat[i][j]<<" ";
}
cout<<endl;
}
}
Help !!