i have tried to do that but could not figure it out ,
lets say i have a set : {1,2,3,4,5}
and i want to have the combinations of 2 elements lik
You can accomplish this using 2 for-loop
s. In the first loop, you iterate through the elements as i
and in the second loop from the value j=i+1
to the end of the count of the number of elements in the set.
It could be something like this:
for (i = 0; i < length_set; i++)
{
for (j = i + 1;length_set; j++)
{
print ("%d%d\n", set[i], set[j]);
}
}
}
NOTE: Its just a pseudocode and i have not checked for syntax, It is just to show the logic.