Swap Two Numbers in PHP
Q. Write a PHP program to swap two numbers using a temp variable
<?php // Define two numbers $a = 10; $b = 20; // Display before swapping echo "Before swapping: a = $a, b = $b<br>"; // Swap using a temporary variable $temp = $a; $a = $b; $b = $temp; // Display after swapping echo "After swapping: a = $a, b = $b"; ?>
Q. Write an algorithm to swap two numbers using a temp variable in PHP
1. Start 2. Define two numbers: a and b 3. Store a in a temporary variable: temp = a 4. Assign b to a: a = b 5. Assign temp to b: b = temp 6. Print the swapped values 7. End
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com