90.5k views
2 votes
1.isodd

$a0– integer value

$v0– integer result

This function must test the value is $a0. If the value in $a0 is odd, then the value of 1 should be assigned to $v0. If the value in $a0 is even, then the value of 0 should be assigned to $v0.

2. getsum

This function must prompt for and read integers until a negative value is read. The function must test each integer to see if it is an odd number. This test must be done by calling isodd (above). The function should return the sum of the even integers in $v0.

User Geisshirt
by
4.3k points

1 Answer

2 votes

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.

User Panache
by
4.3k points