Advertisement
heryan_dp

Cek Ganjil Genap

Oct 20th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.28 KB | None | 0 0
  1. <?php error_reporting(0); ?>
  2. <head>
  3.   <title>Tugas Praktikum 2</title>
  4.  
  5.   <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  6.   <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  7.   <style type="text/css">
  8.     body {
  9.       background-image: linear-gradient(to right, #a1c4fd 0%, #c2e9fb 51%, #a1c4fd 100%) !important;
  10.       padding-top: 1em;
  11.     };
  12.   </style>
  13.   <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  14.   <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  15.   <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
  16.   <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  17. </head>
  18.  
  19. <body>
  20.     <div class="container">
  21.       <div class="row justify-content-md-center">
  22.         <div class="col col-lg-6">
  23.           <h4 class="text-center">Tugas Praktikum 2 - Bilangan Ganjil dan Genap</h4>
  24.           <form action="" method="post">
  25.               <div class="form-group">
  26.                 <label for="nama">Angka Awal</label>
  27.                 <input type="text" autocomplete="off" class="form-control" name="awal" placeholder="Angka Awal" required>
  28.               </div>
  29.               <div class="form-group">
  30.                 <label for="nama">Angka Akhir</label>
  31.                 <input type="text" autocomplete="off" class="form-control" name="akhir" placeholder="Angka Akhir" required>
  32.               </div>
  33.               <div class="form-group">
  34.                 <button type="submit" class="btn btn-primary" name="submit">Proses</button>
  35.               </div>
  36.          </form>
  37.          
  38.          <!-- Info -->
  39.          <div id="info" class="alert alert-warning">
  40.             <?php
  41.                 // Class
  42.                 class coba
  43.                 {
  44.                     // Fungsi
  45.                     public function test($angka1,$angka2)
  46.                     {
  47.  
  48.                         // echo $angka1.' dan '.$angka2;
  49.                         for ($i=$angka1; $i<=$angka2  ; $i++) {
  50.                             if($i%2){
  51.                                 $ganjil[] = $i;
  52.                             }else{
  53.                                 $genap[] = $i;
  54.                             }
  55.                         }
  56.                         echo '<p>Bilangan Ganjil: '. trim(json_encode($ganjil,JSON_NUMERIC_CHECK),'[]') .'</p>';
  57.                         echo '<p>Bilangan Genap: '. trim(json_encode($genap,JSON_NUMERIC_CHECK),'[]') .'</p>';
  58.                     }
  59.                 }
  60.  
  61.                 if (isset($_POST['submit'])) {
  62.                     $a = new coba();
  63.                     echo $a->test($_POST['awal'],$_POST['akhir']);
  64.                 }
  65.  
  66.             ?>
  67.          </div>
  68.         </div>
  69.       </div>
  70.     </div>
  71. </body>
  72. <blockquote class="blockquote text-center">
  73.   <footer class="footer"><h6>Alwi Adib Novianto - 2017103634</h6></footer>
  74. </blockquote>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement