Calculations

PHP subtracting two numbers-PHP program

PHP subtracting two numbers-PHP program

In this tutorial, we will discuss the concept of  PHP subtracting two numbers-PHP program

In this topic, we are going to learn how  to write a program to subtract two numbers  in  PHP programming language

Subtracting two numbers

Find Difference of two numbers

Find difference of two numbers – #1

In this program, the user declare two integer variables $x and $y. Then two numbers are subtracted using minus(-) operator. finally  the result is displayed on the screen

Program 1

<?php
$num1=30;
$num2=15;
$sum=$num1-$num2;
echo "Difference: ".$sum;
?>

When the above code is executed, it produces the following result

Difference: 15

 

Find difference of two numbers – entered by user

In this program, the user asked to enter two numbers(by passing input value to form).  Then two numbers are subtracted using + operator and the result is displayed on the  screen

Program 2

<html>
<body>
<form method = "post">
Enter 1st number
<input type = "number" name="number1"/><br><br>
Enter 2nd number
<input type = "number" name="number2"/><br><br>

<input type = "submit" name="submit" value="Sub"/><br>
</form>

<?php
if(isset($_POST['submit']))
{
    $number1=$_POST['number1'];
    $number2=$_POST['number2'];
    $sub=$number1 - $number2;
    echo "The Difference of $number1 and $number2 is: ".$sub;
    
}

?>

</body>
</html>

When the above code is executed, it produces the following result

PHP subtracting two numbers

Find difference of two numbers – without + operator

In this program, the user asked to enter two numbers(by passing input value to form).  Then two numbers are added using without + operator and the result is displayed on the  screen

Program 3

<body>
<form>
Enter 1st number
<input type = "number" name="number1"/><br><br>
Enter 2nd number
<input type = "number" name="number2"/><br><br>

<input type = "submit" name="submit" value="Sub"/><br>
</form>
</body>

<?php
    @$number1=$_GET['number1'];
    @$number2=$_GET['number2'];
    for($i=1; $i<=$number2; $i++){
        $number1--;
    }
    echo "Difference is: ".$number1;
?>

When the above code is executed, it produces the following result

Subtracting two numbers-PHP program

 

Subtracting two numbers-PHP program

 

Subtracting two numbers

 

Suggested for you

Subtraction of two numbers in Java language

Subtraction of two numbers in C Language

Subtraction of two numbers in C++ Language

Subtraction of two numbers in Python Language

 

Subtraction of two numbers using method in Java language

Subtraction of two numbers using function in C Language

Subtraction of two numbers using function in C++ Language

Subtraction of two numbers using function in Python Language

 

PHP program to add two numbers

PHP program to add two numbers using unction

PHP program to Addition of Two Numbers using function - PHP program
Function to subtract two numbers in PHP
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago