Skip to content

Instantly share code, notes, and snippets.

@hidayat365
Created July 13, 2012 07:49
Show Gist options
  • Save hidayat365/3103450 to your computer and use it in GitHub Desktop.
Save hidayat365/3103450 to your computer and use it in GitHub Desktop.
Problem Deret v2
<?php
// looping terluar untuk menghitung
// angka dari 1 sampai 100 dengan increment 4
for ($i=1; $i<=100; $i+=4) {
// looping dalam untuk menampilkan tiap baris angka
// masing2 baris angka terdiri dari empat bilangan
for ($j=0; $j<4; $j++) {
// cetak angkanya
print $i+$j.' ';
// cetak hurufnya, logikanya
// huruf dicetak saat sisa modulus 4 counter loop dalam bersisa 0 atau 3
// kemudian,
// cetak huhuf 'a' jika modulus 8 counter loop luar kurang dari 4
// cetak huruf 'b' jika modulus 8 counter loop luar lebih dari atau sama dengan 4
if ($j%4==0 or $j%4==3) print $i%8<4 ? 'a ' : 'b ';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment