Cara Membuat bilangan ganjil dan genap dengan php

Monday, September 07, 2015
source kode php
<form method="post">
<input type="text" nama='nilai' placeholder="masukkan bilangan"><br>
<input type="submit" value="hitung">
</form>
<br>
<?php
$nilai=$_POST['nilai'];
echo "Bilangan Genap : <br>";
for ($i=1;$i<=$nilai;$i++){
    if ($i%2==0){
echo $i." ";
}
}
echo "<br>Bilangan Ganjil : <br>";
for ($i=1;$i<=$nilai;$i++){
    if ($i%2==1){
echo $i." ";
}
}?>

Share this

Related Posts

Previous
Next Post »