Last active
January 29, 2025 02:08
-
-
Save Mwamitovi/f67a06daee87acad034cb93a11d7e9b5 to your computer and use it in GitHub Desktop.
Revisions
-
Mwamitovi renamed this gist
Jan 29, 2025 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Mwamitovi created this gist
Jan 29, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,72 @@ <?php // Chapter - 3: Exercises // Question-1 // 1. Without using a PHP program to evaluate them, determine whether each of // these expressions is true or false: // a. 100.00 - 100 // b. "zero" // c. "false" // d. 0 + "true" // e. 0.000 // f. "0.0" // g. strcmp("false","False") // h. 0 <=> "0" // Answer-1 // 1. false // 2. true // 3. true // 4. false // 5. false // 6. true // 7. true // 8. false // Question-2 // 2. Without running it through the PHP engine, figure out what this program prints: // $age = 12; // $shoe_size = 13; // if ($age > $shoe_size) { // print "Message 1."; // } elseif (($shoe_size++) && ($age > 20)) { // print "Message 2."; // } else { // print "Message 3."; // } // print "Age: $age. Shoe Size: $shoe_size"; // Answer-2 // Message 3.Age: 12. Shoe Size: 14 // Question-3 // 3. Use while() to print a table of Fahrenheit and Celsius temperature equivalents // from –50 degrees F to 50 degrees F in 5-degree increments. On the Fahrenheit // temperature scale, water freezes at 32 degrees and boils at 212 degrees. On the // Celsius scale, water freezes at 0 degrees and boils at 100 degrees. So, to convert // from Fahrenheit to Celsius, you subtract 32 from the temperature, multiply by 5, // and divide by 9. To convert from Celsius to Fahrenheit, you multiply by 9, divide // by 5, and then add 32. // Answer-3 $f = -50; while ($f <= 50) { $c = ($f - 32) * (5 / 9); printf("%d degrees F = %d degrees C\n", $f, $c); $f += 5; } // 4. Modify your answer to Exercise 3 to use for() instead of while(). // Answer-4 for ($f = -50; $f <= 50; $f += 5) { $c = ($f - 32) * (5 / 9); printf("%d degrees F = %d degrees C\n", $f, $c); }