0% found this document useful (0 votes)
0 views3 pages

Grade 8 PHP Solutions

This document contains PHP programming exercises for Grade 8, covering various topics such as arithmetic operations, conditional statements, and simple interest calculations. Each section includes code snippets demonstrating how to perform tasks like finding the largest of three numbers, checking if a number is even or odd, and converting temperatures. The exercises aim to reinforce programming concepts and logical thinking in a practical manner.

Uploaded by

Sakshi Gada
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views3 pages

Grade 8 PHP Solutions

This document contains PHP programming exercises for Grade 8, covering various topics such as arithmetic operations, conditional statements, and simple interest calculations. Each section includes code snippets demonstrating how to perform tasks like finding the largest of three numbers, checking if a number is even or odd, and converting temperatures. The exercises aim to reinforce programming concepts and logical thinking in a practical manner.

Uploaded by

Sakshi Gada
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Grade 8 - PHP Programming Worksheet Solutions

1. Arithmetic Operations

<?php

$a = 10;

$b = 5;

echo "Addition: " . ($a + $b) . "\n";

echo "Subtraction: " . ($a - $b) . "\n";

echo "Multiplication: " . ($a * $b) . "\n";

echo "Division: " . ($a / $b) . "\n";

echo "Modulus: " . ($a % $b) . "\n";

?>

2. Largest of Three Numbers

<?php

$a = 10; $b = 20; $c = 15;

if ($a >= $b && $a >= $c) echo "$a is largest";

elseif ($b >= $a && $b >= $c) echo "$b is largest";

else echo "$c is largest";

?>

3. Even or Odd

<?php

$num = 7;

echo ($num % 2 == 0) ? "Even" : "Odd";

?>

4. Positive, Negative or Zero

<?php

$num = -5;

if ($num > 0) echo "Positive";

elseif ($num < 0) echo "Negative";

else echo "Zero";


?>

5. Grade Based on Marks

<?php

$marks = 85;

if ($marks >= 90) echo "Grade A";

elseif ($marks >= 80) echo "Grade B";

elseif ($marks >= 70) echo "Grade C";

elseif ($marks >= 60) echo "Grade D";

else echo "Grade F";

?>

6. Temperature Conversion

<?php

$temp = 100; $unit = "C";

if ($unit == "C") echo "Fahrenheit: " . (($temp * 9/5) + 32);

else echo "Celsius: " . (($temp - 32) * 5/9);

?>

7. Number Range and Checks

<?php

$num = 75;

if ($num >= 1 && $num <= 100) {

if ($num <= 50) echo ($num % 2 == 0) ? "Even" : "Odd";

else echo ($num % 5 == 0 || $num % 10 == 0) ? "Divisible by 5 or 10" : "Not divisible by 5 or 10";

} else echo "Out of range";

?>

8. Leap Year Check

<?php

$year = 2024;

if (($year % 4 == 0 && $year % 100 != 0) || ($year % 400 == 0)) echo "Leap Year";

else echo "Not a Leap Year";


?>

9. Simple Interest Calculation

<?php

$P = 1000; $R = 5; $T = 2;

$SI = ($P * $R * $T) / 100;

echo "Simple Interest: " . $SI;

?>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy