Wednesday, March 11, 2015

Harmonic Sequence Solver in PHP

In this article I would like to share with you a simple program that I wrote in PHP I called this program Harmonic Sequence Solver in PHP. According to Wikipedia.org it is defined as follows In mathematics, the harmonic series is the divergent infinite series: Its name derives from the concept of overtones, or harmonics in music: the wavelengths of the overtones of a vibrating string are 1/2, 1/3, 1/4, etc., of the string's fundamental wavelength.

What our program will do is to ask the user to enter a number and then the user can press the find the harmonic sequence button and then our program will solve and generate the harmonic sequence values using PHP as our programming language.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360




Program Listing

<html>
<title> Harmonic Sequence Solver</title>
<style>
body { 
  font-size:25px; 
  font-family:arial;
  color:blue;
  } 
  
#banner {
  width: 750px;
  background-color: yellow;
  height: 100px;
  margin: 0 auto;
  position: inherit;
  top: 100; 
  left: 0; 
  bottom:0; 
  right: 0;
  padding: 16px 16px;
  
  border-radius: 75px;
  border: 5px solid #fba827;
}
  /* BUTTONS */

#submit {
  background: #0a7d66;
  background-image: -moz-linear-gradient(#0fb493, #0a7d66);
  background-image: -webkit-gradient(linear,left bottom,left top,color-stop(0, #6cbb6b),color-stop(1, #0fb493));
  
  margin: 0 0 0 2px;
  padding: 15px 20px;

  border-radius: 3px 70px 70px 3px;
  -moz-border-radius: 3px 70px 70px 3px;
  border-color: #0fb493 #0da284 #0c9075;

  -moz-box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;
  -webkit-box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;
  box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;  

  font: 16px 'Droid Serif', serif;
  background: #0fb493;
  color: blue;
  cursor: pointer;

  text-shadow: 0 5px 0 rgba(255,255,255,0.4);
}

#submit:hover {       
    background-color: #0fb493;
    background-image: linear-gradient(#0a7d66, #0fb493);
}   

#submit:active {       
    background: #0fb493;
    outline: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;        
}

#submit::-moz-focus-inner {
       border: 0;  /* Small centering fix for Firefox */
}
.inputs {
    -webkit-border-radius: 20px 3px 3px 20px;
    -moz-border-radius: 20px 3px 3px 20px;
    -ms-border-radius: 20px 3px 3px 20px;
    -o-border-radius: 20px 3px 3px 20px;
    border-radius: 20px 3px 3px 20px;

    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -ms-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;
    background: yellow;
    border: 5px solid #fba827;
    color: blue;
    font: 22px 'Droid Serif', serif;
    margin: 0 0 10px;
    padding: 15px 20px 15px 20px;
    width: 150px; 
}
</style>
<?php
$number= $_POST['value'];
error_reporting(0);

 if(isset($_POST['clear'])) {
  $title=""; 
  $values=" "; 
  $results="";
  $number="";
  }



?>
<body style='background-color:lightgreen'>
<div style='width:800px;margin:auto'>
   <div id="banner">
          <h1 align="center">Harmonic Sequence Solver</h1>
      </div>
  <br>
<form action="" method="post">
 Enter a Number : <input id="text" type="text" class="inputs"  type="text" name="value"    value="<?php echo $number; ?>" autofocus  size=5 required/>
   <input  id="submit"  type="submit"  name="check" value="Find Harmonic Sequence" 
  title="Click here to solve harmonic sequence."/>
  <input id="submit"  type="submit" name="clear" value="Clear" 
  title="Click here to clear text box and values on the screen"/>
</form>



<?php 

 if(isset($_POST['check'])) {
echo "<br>";
     $number=0; 
$a=1;
     $result = 0.0;
        
$number= $_POST['value'];

        while($a <= $number)
        {
             echo "1/" .$a." + ";
             $result += + 1 / $a;

             $a++;
        }

      
$results = "Sum of Harmonic Series is " .$result;
   } 
   
   
   echo "<br><br>";
   echo $results;
 ?>
  </body>
</html>


No comments:

Post a Comment