hello!
just started out here...
i need help with this program
i need to generate a 3*3 matrix having unique numbers in the range
1-9. I did this program using srand but i'm unable to get the correct output...i couldn't figure out the error...could someone plz help me??
here the program
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<conio.h>
void main()
{
clrscr();
int a[3][3],i,j,k,l=0,temp,count=0;
int b[9]={0,0,0,0,0,0,0,0,0};
srand(time(NULL));
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
do
{
temp=1+rand()%9;
a[i][j]=temp;
for(k=0;k<9;k++)
{
if(b[k]==temp)
count++;
}
}while(count>0);
b[l++]=temp;
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
getch();
}