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

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

Why is it new people think we're psychic and know what the error you're having is? Don't you think knowing the problem would help with a solution?

All I can assume is you aren't checking to see if a number has already been randomly chosen and loading the same number twice.

i used another array to check if a number has already been chosen but it wasn't giving me unique numbers so i guess my code was wrong...but now i have the code figured out..
i used a do-while loop now to keep iterating till another number which isn't already chosen is selected...thanx anyway

#include<stdio.h>
#include<time.h>
int a[3][3],temp,i,j;
int b[10]={0,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;
}while(b[temp]==1);
b[temp]=1;
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%d",a[i][j]);
printf("\n");
}
}

Edited
by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

Another possible solution is to load your b array with the numbers 1-9. Use rand() to get an index into b and copy the value from b into a .

Now shift all the numbers in b down to overwrite the one just used, leaving only 8 numbers left. The next call to rand() you use 8 instead of 9. Keep doing that until you only have 1 left.

So I am having trouble knowing what to return in the bottom method any help would be appreciated .
Here are the specifications for completing the StringArray class: