[root@rampc rahmat]# cat > piramidaterbalik.php
<?
#!/usr/bin/php
echo "Contoh 1\n";
// testing
for ($i=10;$i>=1;$i--){
if ($i/2!=(int)($i/2)){
for ($x=1;$x<=$i;$x++){
echo " * ";
}
echo "\n";
}
}
echo "\n\n";
echo "contoh 2\n";
$batasMax=9;
for ($i=$batasMax;$i>=1;$i--){
if ($i/2!=(int)($i/2)){
for ($x=1;$x<=$batasMax;$x++){
echo ($x >($batasMax-$i)/2 && $x<=($i+(($batasMax-$i)/2))) ? " * " : " ";
}
echo "\n";
}
}
?>
[CTRL + Z]
<?
#!/usr/bin/php
echo "Contoh 1\n";
// testing
for ($i=10;$i>=1;$i--){
if ($i/2!=(int)($i/2)){
for ($x=1;$x<=$i;$x++){
echo " * ";
}
echo "\n";
}
}
echo "\n\n";
echo "contoh 2\n";
$batasMax=9;
for ($i=$batasMax;$i>=1;$i--){
if ($i/2!=(int)($i/2)){
for ($x=1;$x<=$batasMax;$x++){
echo ($x >($batasMax-$i)/2 && $x<=($i+(($batasMax-$i)/2))) ? " * " : " ";
}
echo "\n";
}
}
?>
[CTRL + Z]
[root@rampc rahmat]# chmode 777 piramidaterbalik.php
Jalankan Script yang telah di buat[root@rampc rahmat]# ./piramidaterbalik.php
Contoh 1
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
contoh 2
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
Contoh 1
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
contoh 2
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
0 komentar:
Posting Komentar