Skip to main content

Practical-04

Write a PHP program to calculate sum of given number.

Introdution

This introduction will discuss how to calculate the sum of a given number in PHP. It will provide a brief overview of the basics of programming in PHP, as well as provide a step-by-step guide for how to use the code to calculate the sum.

Code

<?php
$num1 = 5;
$num2 = 8;

$sum = $num1 + $num2;

echo "Sum of these two numbers is: " . $sum;
?>

Output

Sum of these two numbers is: 13

Explanation

This PHP code gives two variables a value of "5" and "8". It then adds them together with the "+" operator and stores it in a new variable "$sum". Finally, the code echoes the "Sum of these two numbers is:" and the result of the addition.