两个超大整数相加
Given two numbers and we have to find their addition/sum in PHP using a user-defined function.
给定两个数字,我们必须使用用户定义的函数在PHP中找到它们的加法和/和。
PHP code:
PHP代码:
<?php
//function definition
//this function will take two integer arguments
//and return the sum of them
function addTwoNumbers(int $x, int $y)
{
return $x + $y;
}
//calling the function and printing the result
echo " sum of 10 and 25 : " . addTwoNumbers(10, 25);
echo "<br>";
echo " sum of 30 and -10: " . addTwoNumbers(30, -10);
echo "<br>";
?>
Output
输出量
sum of 10 and 25 : 35
sum of 30 and -10: 20
Code explanation:
代码说明:
The function works by using the standard math operation of adding two integers. Whenever we need to call the function, we use the following format addTwoNumbers (x, y); by replacing the values of x and y with two valid integers, we get the resulting sum in the output.
该函数通过使用将两个整数相加的标准数学运算来工作。 每当需要调用该函数时,都使用以下格式addTwoNumbers(x,y); 通过用两个有效的整数替换x和y的值,我们在输出中获得结果总和。
翻译自: https://www.includehelp.com/php/create-a-function-to-find-the-addition-of-two-integer-numbers.aspx
两个超大整数相加