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

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago