Search
 
SCRIPT & CODE EXAMPLE
 

PHP

sum of digits

num = [int(d) for d in input("Enter the Number:")]
sum = 0
for i in range(0, len(num)):
    sum = sum + num[i]

print("Sum of Digits of a Number: {}".format(sum))

# This code is contributed by Shubhanshu Arya (Prepinsta Placement Cell Student) 
Comment

sum digits of number

var value = 2568,
    sum = 0;

while (value) {
    sum += value % 10;
    value = Math.floor(value / 10);
}

console.log(sum);
Comment

Code of getting sum of digits

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

PREVIOUS NEXT
Code Example
Php :: andebol 
Php :: Remove auto generate p from category description 
Php :: laravel store file specifiying name and disk 
Php :: how to get php code from website 
Php :: fuelphp authentication 
Php :: how do i implement blockchain payments on laravel website 
Php :: type of var php 
Php :: Yii2 Dynamic Relational, Lazy loading 
Php :: Jaygaah Free Shipping Woocommerce 
Php :: php get long word in array 
Php :: in ImageRetriever.php line 305 at ImageRetriever-getNoPictureImage(object(Language)) in FrontController.php line 1527 
Php :: get first row of array php 
Php :: WordPress Plugin Code Definition 
Php :: how to type casting and overriding in php 
Php :: Undefined property: CI::$file 
Php :: ph form 
Php :: Route::any 
Php :: WooCommerce Catalog Mode snippets 
Php :: custome route to a page with dynamic parameters wordpress 
Php :: how to get data from two tables in laravel 
Php :: Drupal sync directory in settings.php 
Php :: Round Number Up 
Php :: how to fetch data from database in php and display in pdf 
Php :: Laravel: validate an integer field that needs to be greater than another 
Php :: css dynamique avec php dans page http<style 
Php :: phpdoc array type 
Php :: import csv laravel 8 
Php :: in packagemanifest.php line 131 undefined index name 
Php :: command line that convert html to php file 
Php :: supprimer un cookie avec un input en php 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =