63 076
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #27266 in C++ for Vijay Yadav

Question #27266
program to find out the combination of an element of each array gives a result 0
Expert's answer
$words = array('red', 'blue', 'green');    

$num = count($words);



//The total number of possible combinations


$total = pow(2, $num);



//Loop through each possible combination


for ($i = 0; $i < $total; $i++) {

//For each combination check if each bit is set


for ($j = 0; $j < $total; $j++) {

//Is bit $j set in $i?

if (pow(2, $j) & $i) echo $words[$j] . ' ';

}

echo '<br />';

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions