Thursday, 18 January 2024

Logical Questions

 1.  How to swap 2 variables values with out third variable using PHP?

Ans:  $a = 100; 

          $b = 200;

          $a = $a + $b;  // 100 + 200 = 300
          $b = $a - $b  // 300 - 200  = 100

          $a = $a - $b  // 300 - 100 = 200
Now $a = 200 and $b = 100

2. How to get 4 liters of water by using 3 liters bowl and 5 liters bowl ?

Ans: Step 1: Take 3 liters of water and move it to 5 liters jug. 
         Step2:  Take another 3 liters of water by using 3 lite rs jug and move it to 5 liters jug. Now 3 liters                        jug contains 1 liters of water.

       Step3:  Empty the 5 liters jug and move 1 liter from 3 liters jug to 5 liters jug.

       Step 4:  Take 3 liters of water by using 3 liters jug.

       Step 5: Move 3 liters of water to 5 liters Jug. Now 5 liters Jug contains 4 liters of water.  we got                          required 4 liters of water now

3. 

No comments:

Post a Comment