Search
 
SCRIPT & CODE EXAMPLE
 

PHP

PHP Sum of Digits

<?php  
$num = 14597;  
$sum=0; $rem=0;  
  for ($i =0; $i<=strlen($num);$i++)  
 {  
  $rem=$num%10;  
   $sum = $sum + $rem;  
   $num=$num/10;  
  }  
 echo "Sum of digits 14597 is $sum";  
 ?>
Comment

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");
 

?>
Comment

PREVIOUS NEXT
Code Example
Php :: laravel get latest 
Php :: php et WP_Post Object 
Php :: php read text file into array 
Php :: model get last query in php 
Php :: laravel show table columns 
Php :: laravel eloquent orderby 
Php :: Remove the Breadcrumbs on the Shop Entirely 
Php :: get age in months php 
Php :: why storage link do not work in host for laravel 
Php :: round to 2 decimal places php 
Php :: laravel check if string is url 
Php :: jwt auth laravel auth without password field 
Php :: laravel cache remember 
Php :: unlink(p1): No such file or directory 
Php :: compare dates datetime php 
Php :: php pdo error handling 
Php :: laravel-cors 
Php :: php count 
Php :: valdidate laravel if falid 
Php :: brew reinstall php 7.4 
Php :: fetch method and class in codeigniter 
Php :: cviebrock/eloquent-sluggable 
Php :: laravel pagination vuetify 
Php :: custom rule laravel validation 
Php :: file exist php 
Php :: laravel get current route url 
Php :: how to see php error log 
Php :: php date diff in days 
Php :: php number to words 
Php :: laravel merge two query builder 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =