![]() |
VOOZH | about |
We are going to perform the basic arithmetic operations like- addition, subtraction, multiplication, and division using PHP. We are using HTML form to take the input values and choose an option to perform particular operation using Switch Case.
Arithmetic Operations are used to perform operations like addition, subtraction etc. on the values. To perform arithmetic operations on the data we need at least two values.
Example:
Addition = val + val2 + ... + valn Example: add = 4 + 4 = 8 Subtraction = val - val2 - ... - valn Example: sub = 4 - 4 = 0 Multiplication = val1 * val2 * ... * valn Example: mul = 4 * 4 = 16 Division = val1 / val2 Example: mul = 4 / 4 = 1
Program 1:
Output:
Sum: 45 Diff: -15 Mul: 450 Div: 2
Using Switch Case: The switch statement is used to perform different actions based on different conditions.
Syntax:
switch (n) {
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
case label3:
code to be executed if n=label3;
break;
. . .
case labeln:
code to be executed if n=labellast;
break;
default:
code to be executed if n is different from all labels;
}
Execution Steps:
Program 2:
Output: Open Web Browser and type
👁 Image