Program to find the LCM of a number in PHP with database and form
In this tutorial, we will learn about the followings.- Program to find the LCM of a number in PHP
- Program to find the LCM of a number in PHP with form
- Program to find the LCM of a number in PHP with database
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<html> <body> <form method="POST"> Enter First No. <input type="text" name="num1"> Enter Second NO.<input type="text" name="num2"><br><br> Result: <input type="submit" name="Ok"> </form> </body> </html> <?php if (isset($_POST['Ok'])) { $num1=$_POST['num1']; $num2=$_POST['num2']; $max=($num1>$num2) ? $num1 : $num2; while(1) { if($max%$num1==0 && $max%$num2==0) { echo "LCM of " .$num1. " and " .$num2. " is: ".$max; break; } $max=$max+1; } } //echo '$max'; ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php $num1=3; $num2=4; $max=($num1>$num2) ? $num1 : $num2; while(1) { if($max%$num1==0 && $max%$num2==0) { echo "LCM of " .$num1. " and " .$num2. " is: ".$max; break; } $max=$max+1; } ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<html> <body> <form method="POST"> Enter First No. <input type="text" name="num1"> Enter Second NO.<input type="text" name="num2"><br><br> Result: <input type="submit" name="Ok"> <br><br> </form> </body> </html> <?php $conn=mysqli_connect('localhost','root','','lcm'); if (mysqli_connect_error()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } if (isset($_POST['Ok'])) { $num1=$_POST['num1']; $num2=$_POST['num2']; $max=($num1>$num2) ? $num1 : $num2; while(1) { if($max%$num1==0 && $max%$num2==0) { echo "<input value=$max name=max><br>"; break; } $max=$max+1; } mysqli_query($conn,"INSERT INTO lcm (First,Second,Result) VALUES ('$num1','$num2',$max)"); mysqli_close($conn); } ?> |
