Experiment No. - 1: Date of Performance: Date of Submission
Experiment No. - 1: Date of Performance: Date of Submission
- 1
Experiment No. - 1
PHP script to perform simple arithmetic operations and display the result.
1.1 Aim:
To develop a PHP script that performs basic arithmetic operations (addition, subtraction,
multiplication, and division) and displays the results dynamically.
A PHP script that performs arithmetic operations follows a structured approach that involves
input handling, processing, and output generation.
PHP provides several arithmetic operators that allow mathematical calculations. These operators
work with numeric values (integers and floating points) and return computed results.
1. Variables in PHP
● In PHP, variables are declared using the $ symbol followed by the variable
name.
● PHP is loosely typed, meaning variables do not require explicit data type
declarations.
a. Parentheses ()
b. Exponentiation **
● PHP can handle calculations with integers (whole numbers) and floating-point
numbers (decimals).
● Division by Zero: PHP generates a warning when dividing by zero, which can
be handled using conditional statements.
● Floating-Point Precision Issues: Floating-point calculations may result in
precision errors, which can be controlled using functions like round(), floor(),
or ceil().
<?php
$num1 = 10;
$num2 = 5;
if ($num2 != 0) {
$result = $num1 / $num2;
echo "The Division is: $result";
} else {
echo "Division by zero is not allowed.";
}
?>
</body>
</html>
1.6 Execution Steps:
1. Install a local server like XAMPP or WAMP.
3. Place the file inside the htdocs folder (for XAMPP) or the www folder (for WAMP).
1.7 Output :
1.8 Conclusion :
In conclusion, I have successfully written a PHP code that performs basic arithmetic operations,
such as addition, subtraction, multiplication, and division. This program provides a simple yet
effective way to handle mathematical calculations and demonstrates the practical use of PHP for
solving everyday problems. The code is designed to be efficient, easy to understand, and can be
expanded upon for more complex operations in the future.