62. PHP Program to find the Sum and Product of individual digits of a given number.
How does this program work?
- This program is used to find the sum and product of individual digits of a given number using PHP.
- We can followed by the below code we can get the Output easily.
Here is the code
<html>
<head>
<title>PHP Program To find the Sum and Product of individual digits of given number</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text" name="num1" value="" placeholder="Enter a number"/> </td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$n = $_POST['num1'];
$n1 = $n;
$sum = 0;
$product = 1;
// To calculate Sum and Product
while($n > 0)
{
$dig = $n%10; //To get digit
$sum +=$dig;
$product = $product * $dig;
$n = intdiv($n, 10);
}
echo "Number is : ".$n1;
echo (" The Sum of individual digits of a given number :". $sum);
echo (" The Product of individual digits of a given number : ". $product);
return 0;
}
?>
</body>
</html>