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 make factory 
Php :: php find multiple value in array 
Php :: how to send data from html to php 
Php :: php multiplication 
Php :: json encode php 
Php :: php parse query string 
Php :: move img to public folder in laravel 
Php :: php Program to check if a given year is leap year 
Php :: yii2 gridview action change urls 
Php :: strrev php 
Php :: update cart subtotal woocommerce 
Php :: substr php 
Php :: count column eloquent laravel 
Php :: php curl detect 404 
Php :: xampp php 5.6 download 64 bit 
Php :: PHP MySQL Insert Multiple Records 
Php :: php try json decode 
Php :: foreach smarty 
Php :: keep line breaks in textarea 
Php :: how to download a file in php 
Php :: laravel pdf export 
Php :: php get multiple url parameters 
Php :: php explode empty string 
Php :: how to know if file is empty in php 
Php :: laravel resource api 
Php :: laravel collection except 
Php :: custom pagination in laravel 
Php :: PHP temporary files 
Php :: Rename route resource in laravel 
Php :: copy file in php 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =