Hi all,
what is the best way to obtain all the possible 3-items groups out of 8 elements (0-7) with repetitions?
This would be D'8,3 = 8^3 = 512 groups. I want to save them in an array, like
unsigned int array[512][3];
What is the best approach?
Hi all,
what is the best way to obtain all the possible 3-items groups out of 8 elements (0-7) with repetitions?
This would be D'8,3 = 8^3 = 512 groups. I want to save them in an array, like
unsigned int array[512][3];
What is the best approach?
int array[][]=new int[512][3];
int count=0;
for(int i=0;i<8;i++)
for(int j=0;j<8;j++)
for(int k=0;k<8;k++){
array[count][0]=i;
array[count][1]=j;
array[count][2]=k;
count++;
}
for(int i=0;i<512;i++)
{ System.out.print("array["+i+"]:");
for(int j=0;j<3;j++)
System.out.print(array[i][j]+" ");
System.out.println("");
}
In C:
unsigned int array[][]=new int[512][3];
int count=0;
int i,j,k;
for(i=0;i<8;i++)
for(j=0;j<8;j++)
for(k=0;k<8;k++){
array[count][0]=i;
array[count][1]=j;
array[count][2]=k;
count++;
}
for(i=0;i<512;i++)
{
printf("\n array[%d]:",i);
for(j=0;j<3;j++)
printf("%d",array[i][j]);
}
Thanks for the reply biswajit_cs07, very appreciated.
PS: "new" operator doesn't exist in C. :)
Sorry I did not check the code. Just converted it from java to C without compilation.
Ya there is no new operator in C. If you know that you can easily rectify it.
Thanks.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.