Showing posts with label factoring of numbers in php. Show all posts
Showing posts with label factoring of numbers in php. Show all posts

Sunday, February 19, 2017

Factors of a Numbers in PHP

Hi there in this article I would like to share with you a sample program that will compute the factors of a given number in PHP. The code is very short and easy to understand. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.





Sample Program Output


Program Listing



<html>
<title> Factors of a Number </title>
<style>
body {
 font-family:arial;
 font-size:20px;
}
</style>
<body bgcolor="lightgreen">
<br> <br>
<?php
$val = $_POST['number'];

?>
<h3> Factors of a Number in PHP </h3>
<form method="POST" action="">
    <input type="text" name="number" value="<?php echo $val;?>" placeholder="Give a Number"></input>
    <br> <br>
    <input type="submit" value="OK"></input> &nbsp;&nbsp;&nbsp;
     <input type="submit" name="clear" value="Clear"></input>
</form>
<?php

  if(isset($_POST['clear']) && !empty($_POST['clear'])) {
   $display = " ";
   $val = " ";
   $a=" ";
   }
   
if(isset($_POST['number']) && !empty($_POST['number'])) {
         
       $display = "The Factors of $val is ";
       echo $display;
     for($a=1; $a <=$val; $a++)
    {
        if ($val%$a == 0)
        {
           
            echo  " ".$a." ";
        }
        }
 }             

?>
</body>
</html>