[Solved] Add and Subtract - PHP Function Task

  

4
Topic starter

You will receive 3 integers. Write a function sum to get the sum of the first two integers and subtract function that subtracts the third integer from the result from the Sum function.

Examples:

add and subtract php function task

1 Answer
3

Here is my answer:

<?php
 
$number1 = intval(readline());
$number2 = intval(readline());
$number3 = intval(readline());
$endResult = addAndSubtract($number1, $number2, $number3);
 
echo $endResult;
 
function addAndSubtract($n1, $n2, $n3) {
    $result = 0;
    $result += $n1 + $n2;
    $result -= $n3;
    return $result;
}
Share: