Answer:
<?php
function isodd($a0){
if($a0%2==0)
$v0=0;
else
$v0=1;
return $v0;
}
function getsum(){
$sum=0;
while(1){
echo "Enter a number: ";
$input = rtrim(fgets(STDIN));
if(isodd($input)==0){
$sum+=$input;
}
if($input<0)
break;
}
return $sum;
}
echo "Sum of all even numbers is: ".getsum();
?>
Step-by-step explanation:
- Use a conditional statement to check if the number is even or not
- Inside an infinite while loop , check if number is even then add the input to sum variable.
- Otherwise if input is negative then return back from loop.
- Finally display sum of all even numbers.