Last active
December 17, 2017 02:44
-
-
Save piharpi/e28be90178cc8f83a85a33b9ef28ec64 to your computer and use it in GitHub Desktop.
PHP Mencari Bilangan Ganjil
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Clue : Karena syarat bilangan ganjil adalah jika bilangan itu di bagi 2 sisa 1 | |
for ($x=1; $x <= 10; $x++){ // Mengulang selama 10 kali yang di mulai dari angka 1 | |
if ( $x % 2 == 1 ){ // Mengecek apakah bilangan itu dibagi 2 sisa 1 | |
echo " ".$x; // Jika benar bilangan itu di bagi 2 sisa 1 maka menampilkan bilangan itu dengan diikuti string kosong | |
} | |
} | |
# Hasil : 1 3 5 7 9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment