Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php Program for Sum of the digits of a given number

<?php
// PHP Code to compute sum
// of digits in number.
 
// Function to get
// $sum of digits
function getsum($n)
{
    $sum = 0;
    while ($n != 0)
    {
        $sum = $sum + $n % 10;
        $n = $n/10;
    }
    return $sum;
}
 
// Driver Code
$n = 687;
$res = getsum($n);
echo("$res");
 

?>
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #php #Program #Sum #digits #number
ADD COMMENT
Topic
Name
5+4 =