🔒 Closed [HELP] PHP Code

Status
Not open for further replies.

rakhistha

Established
I need help sana with this problem. Though madali lang xa kung iintindhin..kasi FOR LOOP lang tapos it connects with ODD and EVEN numbers..kaso hindi ko alam kung pano ko ipapasok ung code. patulong po..

eto ung dapat magenerate na output. ang nagagawa ko palang is eto.


<?php
$x = 'STEP';
$y = 'VALUES';

echo "$x&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp$y<br>";

for ($x = 1; $x <= 10; $x++) {
if ($x % 2 == 2){
echo $x * 10;
}
echo "$x <br>";

}

?>

hindi ko alam kung saan ko ipapasok ung odd and even numbers.

1618116860526.webp
 
nope mam..as you can see dun sa dapat na generated output. Sa kabila dun sa $step continuous from 1 to 10, now if statement, if the value in $step is odd it multiply by 10 (*10) next loop..so papasok c x++; $step is even number %2 == 0 mag aadd siya dun sa previous number which is 1..hmmmmmmmmm.....
 
PHP:
<?php

$limit = 10;

for ($i = 1; $i <= $limit; $i++) { 
    if (IsOdd($i)) {
        echo $i*10;
    }else{
        echo $sum = $i + ($i-1);
    }
    echo "</br>";
}

function IsOdd($step){
    return ($step % 2 != 0) ? true:false;
}
?>


ikaw na bahala sa printing ng output mo
 
Status
Not open for further replies.

About this Thread

  • 4
    Replies
  • 432
    Views
  • 2
    Participants
Last reply from:
rakhistha

Online now

Members online
1,023
Guests online
1,452
Total visitors
2,475

Forum statistics

Threads
2,277,057
Posts
28,974,016
Members
1,229,706
Latest member
mxmmo
Back
Top