How To Implement PHP Program To Find Sum Of Digits

admin_img Posted By Bajarangi soft , Posted On 27-11-2020

Using php and javascript we can find sum of digits of a number just add all the digits. For example, 222 = 2 + 2 + 2 222 = 6

How To Implement PHP Program To Find Sum Of Digits

Complete Code For Implement PHP Program To Find Sum Of Digits.

<!DOCTYPE html>
<html>
<head>
    <title>How Do I Convert From Mach To Knots Using Javascript</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<style>
    body {
        background: black;
    }

    .form-control {
        width: 80%;
    !important;
    }
</style>
<body>
<body>
<div class="container">
    <br/><br/>
    <div class="text-center">
        <h1 id="color" style="color: white;">Convert From Mach To Knots Using Javascript</h1>
    </div>

    <div class="well">
        <form name="num"  action="#" method="POST">
            <input class="form-control" type="text" name="num" />
        </form>
       
        <?php
        if(isset($_POST['num']))
        {
            $num = $_POST['num'];
            $sum=0; $rem=0;
            for ($i =0; $i<=strlen($num);$i++)
            {
                $rem=$num%10;
                $sum = $sum + $rem;
                $num=$num/10;
            }
            echo "Sum of digits is $sum";
        }
        ?>
        
    </div>
</div>
</body>
</html>

Related Post