Page 249 - Computer Software Application TP - Volume 1
P. 249

COMPUTER SOFTWARE APPLICATION - CITS




           1  Create a PHP if statement to determine whether a variable $temperature is greater than 30 degrees Celsius
              then display “It’s hot outside!”
           2  Create a PHP program that determines whether a student has passed or failed an exam based on their
              score. If the score is greater than or equal to 60, display a “Pass” message; otherwise, display a “Fail”
              message.
           3  Write a PHP if statement to determine if a variable $num is divisible by 2 and 3. If it is, echo “The number is
              divisible by both 2 and 3”, otherwise echo “The number is not divisible by both 2 and 3”.
           4  Write a PHP switch statement that checks the value of a variable $dayOfWeek and echoes “It’s a weekday”
              for Monday to Friday, and “It’s a weekend” for Saturday and Sunday.
           5  Write a PHP switch statement to determine the discount percentage based on the quantity of items
              purchased. If the quantity is 1-10, apply a 5% discount, if it’s 11-20, apply a 10% discount, and if it’s over 20,
              apply a 15% discount.
           6  Write a PHP ternary operator statement to determine if a given number stored in $num is even or odd, and
              echo “Even” if it’s even, otherwise echo “Odd”.
           7  Write a PHP while loop that calculates the factorial of a given number $n and echoes the result.
           8  Create a PHP while loop that generates Fibonacci numbers until reaching a value greater than 1000, and
              echoes each Fibonacci number.
           9  Create a PHP for loop to generate multiples of 2 and 3 in between 1 and 100, and echoes each number.
           10 Write a PHP script using nested for loops to create a simple multiplication table (e.g.,  1x1=1, 1x2=2, ...,
              5x5=25).

           11 Create a script with nested for loops. The outer loop iterates 3 times, and the inner loop iterates 5 times.
              Inside the inner loop, use break to exit the entire loop structure (both inner and outer) if the current iteration
              number in the inner loop reaches 3.














































                                                           234

                               CITS : IT & ITES - Computer Software Application - Exercise 51
   244   245   246   247   248   249   250   251   252   253   254