🔒 Closed [HELP] PHP Code

Status
Not open for further replies.

rakhistha

Forum Veteran
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
  • 461
    Views
  • 2
    Participants
Last reply from:
rakhistha

Trending Topics

Online now

Members online
788
Guests online
1,982
Total visitors
2,770

Forum statistics

Threads
2,332,309
Posts
29,263,990
Members
1,146,203
Latest member
xia___
Back
Top