Showing posts with label menghitung. Show all posts
Showing posts with label menghitung. Show all posts
Monday, August 29, 2016
Cara Membuat Perulangan Menghitung Faktorial For While dan Do While pada PHP
Cara Membuat Perulangan Menghitung Faktorial For While dan Do While pada PHP

Assalammualaikum Wr. Wb..
Kali ini saya akan mengeshare Cara Membuat Perulangan Menghitung Faktorial For While dan Do While pada PHP. sebelumnya komputer/laptop anda harus terinstall XAMPP dan Notepad++ terlebih dahulu. Jika sudah terinstall silahkan buat file .php menggunakan Notepad++ Anda.
- Sebelum copy paste silahkan buat folder di C:/xampp/htdocs/ dengan nama folder perulangan.
- Sebelumnya kita buat dulu css nya. biar tampilannya tidak seperti zaman purba.
body{
color:#000;
background:-webkit-linear-gradient(top,red,orange,yellow,green);
background:-moz-linear-gradient(top,red,orange,yellow,green);
background:-o-linear-gradient(top,red,orange,yellow,green);
background-attachment:fixed;
font-size:18px;
font-family: Tahoma, sans-serif;
margin:0;
padding:48px;
}
h2{
color:blue;
}
h2:hover{
color:red;
}
a,a:visited{
color:blue;
text-decoration:none;
}
a:hover{
color:red;
text-shadow:0 2px 6px #888;
}
.panel{
max-width:480px;
background-color:skyblue;
margin:1px auto 1px;
padding:24px;
border-radius:8px;
-webkit-border-radius:8px;
-moz-border-radius:8px;
box-shadow:0 4px 8px #000;
}
input{
border-radius:8px;
-webkit-border-radius:8px;
-moz-border-radius:8px;
font-size:18px;
padding:8px 14px;
margin:0 1px;
border:1px solid #888;
}
.field{
width:320px;
}
.tombol{
color:#fff;
background-color:#000;
}
.tombol:hover{
background-color:orange;
}
- Simpan di C:/xampp/htdocs/perulangan dengan nama style.css
A. MEMBUAT PERULANGAN MENGHITUNG FAKTORIAL MENGGUNAKAN FOR
- Silahkan copy paste script berikut :
<html>
<head>
<title>Menghitung Bilangan Faktorial menggunakan For pada PHP</title>
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<body>
<?php
$n = isset($_POST[n]) ? $_POST[n] : NULL;
if(isset($_POST[submit])){
if($n!=NULL){
$bil = 1;
for($i=1;$i<=$n;$i++){
$bil = $bil*$i;
}
}else{
$bil = Bilangan Tidak boleh kosong mblo!;
}
}
date_default_timezone_set(Asia/Jakarta);
echo <div class="panel">;
echo <h2>Menghitung Bilangan Faktorial menggunakan For</h2>;
echo date("l, d-M-Y H:i:s");
echo <hr>;
echo <h4>Masukkan Bilangan :</h4>;
echo <form action="" method="post">;
echo <input class="field" type="text" name="n" value=".$n." placeholder="Masukkan Bilangan..."/>;
echo <input class="tombol" type="submit" name="submit" value="Hitung"/>;
echo </form>;
if((isset($n))and($n!=NULL)){
echo <h4>Hasil Faktorial :</h4>;
echo => ;
for($i=1;$i<$n;$i++){echo $i.x;}
echo $n;
echo <br/>;
}
echo <h4>Jumlah Faktorial :</h4>;
echo <input class="field" type="text" value=".(isset($bil) ? $bil : NULL)." readonly/>;
echo <hr>;
echo <a href="../">« Kembali</a>;
echo <hr>;
echo <center><a href="http://syahrulzzadie.blogspot.com" target="blank_">© Syahrulzzadie</a></center>;
echo </div>;
?>
</body>
</html>
- Simpan di C:/xampp/htdocs/perulangan dengan nama for.php
- Silahkan Buka web browser anda (Google Chrome atau Mozilla). lalu ketikan http://localhost/perulangan/for.php
- Maka hasilnya seperti ini :
B. MEMBUAT PERULANGAN MENGHITUNG FAKTORIAL MENGGUNAKAN WHILE
- Silahkan copy paste script berikut:
<html>
<head>
<title>Menghitung Bilangan Faktorial menggunakan While pada PHP</title>
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<body>
<?php
$n = isset($_POST[n]) ? $_POST[n] : NULL;
if(isset($_POST[submit])){
if($n!=NULL){
$bil = 1;
$i=0;
while($i<$n){
$i++;
$bil = $bil*$i;
}
}else{
$bil = Bilangan Tidak boleh kosong mblo!;
}
}
date_default_timezone_set(Asia/Jakarta);
echo <div class="panel">;
echo <h2>Menghitung Bilangan Faktorial menggunakan While</h2>;
echo date("l, d-M-Y H:i:s");
echo <hr>;
echo <h4>Masukkan Bilangan :</h4>;
echo <form action="" method="post">;
echo <input class="field" type="text" name="n" value=".$n." placeholder="Masukkan Bilangan..."/>;
echo <input class="tombol" type="submit" name="submit" value="Hitung"/>;
echo </form>;
if((isset($n))and($n!=NULL)){
echo <h4>Hasil Faktorial :</h4>;
echo => ;
$i=0;
while($i<$n-1){
$i++;
echo $i.x;
}
echo $n;
echo <br/>;
}
echo <h4>Jumlah Faktorial :</h4>;
echo <input class="field" type="text" value=".(isset($bil) ? $bil : NULL)." readonly/>;
echo <hr>;
echo <a href="../">« Kembali</a>;
echo <hr>;
echo <center><a href="http://syahrulzzadie.blogspot.com" target="blank_">© Syahrulzzadie</a></center>;
echo </div>;
?>
</body>
</html>
- Simpan di C:/xampp/htdocs/perulangan dengan nama while.php
- Silahkan Buka web browser anda (Google Chrome atau Mozilla). lalu ketikan http://localhost/perulangan/while.php
- Maka hasilnya seperti ini :
C. MEMBUAT PERULANGAN MENGHITUNG FAKTORIAL MENGGUNAKAN DO WHILE
- Silahkan copy dan paste script berikut:
<html>
<head>
<title>Menghitung Bilangan Faktorial menggunakan Do While pada PHP</title>
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<body>
<?php
$n = isset($_POST[n]) ? $_POST[n] : NULL;
if(isset($_POST[submit])){
if($n!=NULL){
$bil = 1;
$i=1;
do
{
$bil = $bil*$i;
$i++;
}
while($i<=$n);
}else{
$bil = Bilangan Tidak boleh kosong mblo!;
}
}
date_default_timezone_set(Asia/Jakarta);
echo <div class="panel">;
echo <h2>Menghitung Bilangan Faktorial menggunakan Do While</h2>;
echo date("l, d-M-Y H:i:s");
echo <hr>;
echo <h4>Masukkan Bilangan :</h4>;
echo <form action="" method="post">;
echo <input class="field" type="text" name="n" value=".$n." placeholder="Masukkan Bilangan..."/>;
echo <input class="tombol" type="submit" name="submit" value="Hitung"/>;
echo </form>;
if((isset($n))and($n!=NULL)){
echo <h4>Hasil Faktorial :</h4>;
echo => ;
$i=1;
do{
echo $i.x;
$i++;
}while($i<$n);
echo $n;
echo <br/>;
}
echo <h4>Jumlah Faktorial :</h4>;
echo <input class="field" type="text" value=".(isset($bil) ? $bil : NULL)." readonly/>;
echo <hr>;
echo <a href="../">« Kembali</a>;
echo <hr>;
echo <center><a href="http://syahrulzzadie.blogspot.com" target="blank_">© Syahrulzzadie</a></center>;
echo </div>;
?>
</body>
</html>
- Simpan di C:/xampp/htdocs/perulangan dengan nama do_while.php
- Silahkan Buka web browser anda (Google Chrome atau Mozilla). lalu ketikan http://localhost/perulangan/do_while.php
- Maka hasilnya seperti ini :
Atau Anda juga bisa Download ZIP filenya disini.
Sekian dari saya, Terima kasih telah berkunjung. Semoga Bermanfaat.
Wassalammualaikum Wr. Wb.
Contoh Kuis Menghitung Operasi Aritmatika Menggunakan PHP
Contoh Kuis Menghitung Operasi Aritmatika Menggunakan PHP

Kali ini saya akan membagikan contok script mengitung opreasi aritmatika menggunakan PHP.
Sebagai Contoh :
Toko Bangunan Abadi Jaya menjual :
Cat A : 75,000/kaleng
Cat B : 125,000/kaleng
Cat C : 250,000/kaleng
Pak budiman ingin membeli Cat B sebanyak 2 kaleng dan cat C 3 kaleng.
Dalam setiap pembelian di toko ini, pembeli dikenakan pajak PPN sebesar 10%.
Yuk, bantu Pak Budiman untuk menghitung harga totalnya.
Untuk menjawab penyataan diatas kita harus membuat variabel-variabel pada soal diatas.
untuk lebih lengkapnya. Berikut Script PHP nya :
<?php
echo <h1>Kuis Aritmatika</h1>;
$cat_a = 75000;
$cat_b = 125000;
$cat_c = 250000;
$beli = (($cat_b*2)+($cat_c*3));
$ppn = $beli*(10/100);
$bayar = $beli+$ppn;
$bayar = number_format($bayar,2);
$beli = number_format($beli,2);
$ppn = number_format($ppn,2);
echo Harga Normal : Rp. .$beli.<br/>;
echo PPN : Rp. .$ppn.<br/>;
echo Harga Totalnya : Rp. .$bayar;
?>
Copy Script diatas, lalu Paste kan di Notepad++ dan Jalankan di Web browser localhost anda.
Maka hasilnya seperti ini :

Wassalamualaikum Wr.Wb.
Labels:
aritmatika,
contoh,
kuis,
menggunakan,
menghitung,
operasi,
php
Subscribe to:
Posts (Atom)