PHP program to subtract two numbers using function
Table of Contents
In this article, we will discuss the concept of PHP program to subtract two numbers using function
In this post, we are going to learn how to write a program to find subtraction of two numbers using function in PHP language
Program 1
In this program, first the user declare variables as parameter in function. Then when the user call the function, passing the values to variables as argument. finally , the result is calculated and display on the screen
<html>
<head>
<title> Subtraction of two numbers</title>
</head>
<body>
<?php
//function definition
function subTwoNumbers($x, $y)
{
return $x - $y;
}
//Calling the function and print result
echo "Difference of 200 and 30: ".subTwoNumbers(200,30);
echo "<br>";
echo "Difference of 150 and 550: ".subTwoNumbers(150,550);
echo "<br>";
echo "Difference of 100 and -40: ".subTwoNumbers(100,-40);
echo "<br>";
?>
</body>
</html> When the above code is executed, it produces the following result
Difference of 200 and 30: 170 Difference of 150 and 550: -400 Difference of 100 and -40: 140
In this code, we are going to learn how to write a program to calculate difference of two numbers using function in PHP programming language
Program 1
In this program, first the user declare variables as parameter in function. Then when the user call the function, passing the values to variables as argument. finally , the result is calculated and display on the screen
<head>
<title> Subtraction of two numbers</title>
</head>
<body>
<h3>PHP Subtract two numbers using function</h3>
<?php
//function definition
function subTwoNumbers($x, $y)
{
$sub=$x - $y;
return $sub;
echo $sub;
}
//Calling the function and print result
echo "The Difference of 10 and 300: ";
echo subTwoNumbers(10,300);
echo "<br>";
echo "The Difference of 200 and 120: ";
echo subTwoNumbers(200,120);
echo "<br>";
echo "The Difference of 100 and -200: ";
echo subTwoNumbers(100,-200);
echo "<br>";
?>
</body>
</html> When the above code is executed, it produces the following result
PHP Subtract two numbers using function
The Difference of 10 and 300: -290 The Difference of 200 and 120: 80 The Difference of 100 and -200: 300
Suggested post
Subtract two number in Java language
Subtract two number in C language
Subtract two number in C++ language
Subtract two number in Python language
Sum of two integers using function in C#
Sum of two floating point numbers in C#
Addition two number in Java language
Addition two number in C language
Addition two number in C++ language
Addition two number in Python language
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.