Loading...
Friday, March 14, 2014

Contoh Program Piramida Bolak-Balik di PHP

<html>
<head>
<title>Gambar</title>
</head>
<style>
body{
margin: 0;
background:url(bg1.jpg) top right no-repeat;
background-attachment:fixed;
}
td,th{
padding: 15px;
}
#kotak1{
height: 100%;
margin: 0;
}
#kotak2{
background:url(bg.jpg) top right no-repeat;
position: relative;
text-align: center;
padding:40px;
width: 80%;
margin:auto;
top:10%;
border-radius: 20px;
border: #000 double 4px;
}
</style>
<SCRIPT LANGUAGE="JavaScript">
function validate()
{
submitOK="True"
x=document.tugas

jumlah=x.jumlah.value
if (jumlah%2==0)
{
alert("Angka Harus ganjil!")
submitOK="False"
}
if (submitOK=="False")
{
return false
}
}
</script>
<body>
<div id="kotak1">
<div id="kotak2">
<?php
echo "<table border=\"5\"><td align=center>
<form name='tugas' onSubmit='return validate()' method='POST' action='".$_SERVER['PHP_SELF']."'>
Inputkan bilangan<br><input name='jumlah'/><br><input type='submit' value='Lihat'>
</form></td>";

//GAMBAR
echo "<td align=center width=\"1000px\">";

if(!isset($_POST['sumbit']))
{
if(empty($_POST['jumlah']))
{
echo"SILAHKAN MASUKAN ANGKA PADA KOLOM DISAMPING!";
}
else if(!empty($_POST['jumlah']))
{
$n=$_POST['jumlah'];

$cek = -1;
$cek2 = $n+2;;
for($i=$n;$i>0;$i--)
{
switch ($i){
case 1:$warna = "red";break;
case 2:$warna = "green";break;
case 3:$warna = "blue";break;
case 4:$warna = "cyan";break;
case 5:$warna = "magenta";break;
default :$warna = "rgb(".($i*$i*2).",".($i*$i).",".($i).")";
}
if($i > $n/2)
{
$cek+=1;
$cek2-=2;
}
else
{
$cek-=1;
$cek2+=2;
}
echo "<font style=font-size:".(30)."px;color:$warna>";
for($j=0;$j<$cek;$j++) echo "=";
for($j=0;$j<$cek2;$j++) echo "*";
for($j=0;$j<$cek;$j++) echo "=";
echo "<br/>";
}
}
}
echo "</font></td>";
?>
</div></div>
</body>
</html>

OUTPUT













0 comments:

Post a Comment

 
TOP