sum the digits of an integer

Solutions on MaxInterview for sum the digits of an integer by the best coders in the world

showing results for - "sum the digits of an integer"
Niklas
25 Jul 2016
1function digSum(n) {
2    let sum = 0;
3    let str = n.toString();
4    console.log(parseInt(str.substring(0, 1)));
5    for (let i = 0; i < str.length; i++) {
6        sum += parseInt(str.substring(i,i+1));
7        
8    }
9    return sum;
10}
Karissa
17 Nov 2016
1num = [int(d) for d in input("Enter the Number:")]
2sum = 0
3for i in range(0, len(num)):
4    sum = sum + num[i]
5
6print("Sum of Digits of a Number: {}".format(sum))
7
8# This code is contributed by Shubhanshu Arya (Prepinsta Placement Cell Student) 
Sana
24 Jul 2017
1def getSum(n)
2  n.digits.sum
3end
4
5print "Sum of digits = ", getSum(555);
Shaima
30 Oct 2016
1#include <stdio.h>
2 
3int getSum(unsigned long long n) {
4    int sum = 0;
5    for (; n; n /= 10)
6    	sum += n % 10;
7    return sum;
8}
9
10int main(){
11	printf("Sum of digits = %d\n", getSum(555));
12}
queries leading to this page
how to find the sum of digitscalculating sum of digit of a number how to sum of 4 digit numbers find sum of digitsyou 27re given an integer n write a program to calculate the sum of all the digits of nnumbers sum in digitsum of all possible 4 digit numbers with digits 2 2c3 2c3 and 4 using each digit only oncesum the digits in an integercalculate sum of digits of number in o 281 29compute the sum of the digits of a numbersum of digits including 10program for result of digitssum of digits fomulainteger and then prints the number and the sum of its digits compute sum of digits in all numbers from 1 to nnumber digits sumcalculate digit sum of a numbersum of digits of a number onlinehow to find sum of digit of numberwrite a program to find the sum of individual digits of a given number fastest way to find sum of digits of a numbercode for sum of digitssum number digitsum digits onlinefind the sum of all 4 digit numbers formed by taking all the digits 2 2c 4 2c 6 and 8 write a program to find the sum of digits of a numbersum all the digits in the numberprogram to find sum of digits of a number reducing into single digithow to find the sum of all the digits in asumming up the digitshow to find the sum of digits of a numbersum of numbers of an intsum of the digit numberwrite a program to calculate the sum of the digits of a given number infind sum of digits in a numberwrite a program that reads a positive integer and prints the sum of squares of each digit in the number what is the sum of of all digit used to write all two digittake a number and sum its digitssum of a digits of numberif number of 9 digit numbers 2c the sum of whose digits is 4 is n then find the value ofsum of digits to single digitprogram to sum of digitssum of all the digits of a number is eqaul to that numberhow to find the digit sum of of 3 digit numberfind the sum of given numbers digitsum of the digit o a umberwrite a function digitsum that calculates the digit sum of an integer the digit sum of an integer is the sum of all its digits example 3a digitsum 28192 29 should return 12 given a number a 2c we need to find sum of its digitsdetermine the sum of al digits of ndigits sumsum of digits of a number is 9a number consists of two digits whose sum is 15 if 9 is added to the number 2c then the digits change their places the number isevaluate the sum of all the 4 digit numbers that can be formed with the digits 1 2c3 2c 5 and 7 write a program that gets a number and then calculates sum of its digits what is the sum of all digits used to write all two digit number onceyou 27re given an integer n write a program to calculate the sum of all the digits of n the sum of all the possible numbers of 4 digits formed by digits 3 2c 5 2c 5 2c and 6 using each digit once isfind the sum of all 4 digit numbers formed by taking all the digits 2 2c 4 2c 5 and 7 exactly once 0 the sum of a two digit number and the number formed by interchanging the digit is 132 if 12 is added to the number 2c the new number becomes 5 times the sum of digits find the number what is sum of number digitsthe sum of digits of number 10 5en 1 is 3798 value of n iscalculate sum of digits of a number such that number becomes single digitprogram that compute the value of the sum of the digits in an integergiven a digit n and an integer number s u m 2c print all the n digit numbers with their digit sum equal to the given s u m digit sum is defined as the sum of all digits of the number sum of digits of a number upto single digitsum 3dsum 2bdigit 2510 3bdigit 3ddigit 2f10 3bsum 3dsum 2bdigit 2510 3bdigit 3ddigit 2f10 3bsum 3dsum 2bdigit 2510 3bdigit 3ddigit 2f10 3b in c program that gives sum of digits of a numberprogram to find the sum of digitshow to calculate sum of digits of a numbersum of digits recusrionturn a number into the sum of its digitsthe sum of a two digit number and the number formed by interchanging the digit is 132 if 12 is added to the number 2c the new number becomes 5 times the sum of the digits sum of digits find the number what is the sum of of all digits used to write all two digit number ones2 sum of digits of a numberlet s be the sum of the digits of the numbersum of digits in number onlinehow to take sum of digits of numberhow to print all n digit numbers whose sum of digits equals to given suma two digit number is 6 times the sum of its digits sum of its digits is added to number 2c result is 63 what is the numbercalculate sum of digits of a number formulasum the digits of an integerimplement the method sum so thatgiven length and sum of digitssum of digits of 4 digit numberhow to calculate sum of all digits in a given number what is the sum of the digits of integer x 2c where x 3d 810 c3 97 526 3fgiven an integer with 3 digits 2c find its sum of digitssum of digit of a number geeks for geekscalculate the sum of the digits in an integerthe sum of all the possible numbers of 4 digits formed by digits 3 2c 5 2c 5 2c and 6 using each digit once igiven a number find the sum of its digitssum of digit in o 281 29function to calculate sum of digits of a numberthen prints the number and the sum of its digitssum of all digits of a numbersum of digits propertiesnumber of digits in sumsum of the digits what is the sum of the digits of integer x 2c where x 3d 8 5e10 c3 97 5 5e26 3fcalculate sum of digits of integersum of digits formulafind the number of 6 digits numbers whose sum is 10 2c using the digits 1 2c 2 2c 3 only program to calculate sum of all digits in a given numberto find the sum of digits of a numberfind the sum of digits of a numberfind the sum of all possible 4 digit numbers that can be formed by using the digits 1 2c3 2c5 2c7sum of numbers in digitscode for sum of digits algorithmwrite a program to take a number and calculate the sum of digit of a number write a function digitsum that calculates the digit sum of an integer the digit sum of an integer is the sum of all its digits program to find the sum of digits of a given number algorithmsum of digits in numbergiven a set of digits 2c find sum of all n digit numbers whose each digit belong to given set of digits sum of all numbers formed from given digitssum of digit of a number in o 281 29write a function that finds the sum of the digits in any given integer f 28n 2cb 29 be the sum of digits of the integer n when written in base b compute the sum of digits in a given integer4 sum of digits of a numberlet m be the sum of all possible 4 digit numbers with different digits formed from digits 1 2c 2 2c 3 2c 4 sum of its digitsget number of digits in a number and sum of digitssum of digits algorithmthe sum of the digits write a program to find the sum of all the digits of a number write a program to calculate sum of digits of a numbersum of digits in c 2b 2b digits are 10 5e5given integers a and b find the sum of digits find the sum of the digits of a four digit number 28ex 1234 sum 3d10 29 28without using a loop 29 sum of the digit int sum of digits 28int n 29if sum of digits of a number is 1sum of sum of digitsgiven length and sum of digits solutionfunction to obtain sum of digits in a given numbersum of digits methodfind the sum of the digits in the number 1000 21sum digits of integerhow to find the sum of the digitsprogram to calculate sum of digits of a numbersum a digit of numbergiven a number 2c 22sumdigits 22 returns the sum of all its digitssum of digitsum of all numbers of a digitprogram to find sum of symetric digits that is equal to number of digitfunction to get sum of digits in a numberhow to add digit of a given numberhow to get the sum of digits formulasum of digitsdigit and sum of digithow to find sum of digits of a numberwrite a program to find out sum of digits of given number how to find the one digit sum of a numberfind numbers whose sum of digits is 1sum of numbers formed by digitssum of all digits in numberfind number given sum of digits and number of digitscompute the sum of all digits in n that are 6or7the sum of the digits of the numberwhat is the sum of the digits of the number 21000calculate sum of digits of a numberfind the sum of all 4 digit numbers formed by taking all the digits 2 2c 4 2c 6 and 8find sum of all digits of a numbersum of digit of numberthe summation of digits of a given numbersum digitsfinding sum of digits of a numberwhat does the sum of the digits of the number meanwrite an algorithm to find sum of digits of a numbersum of all the digits of a numbersum of digits of a numbersum of digits of a number x and ysum digits of a numberwhat is the sum of all the 4 digit numbershow to find sum of digits of numbers using 25the sum of the digits in n 21find the sum of all the 4 digit numbers that can be formed with the digits 3 2c 4 2c 5 and 6find sum of digits of a numbersum of the digits in numbersum of the digits of a number is 9what is the sum of the digits of the integer equal towhat is the sum of the digitsnumber with given sum of digitfind sum of digits algorithmimplement the function sum digits 2c which should return the sum of all digits of an integer received as a parameter how sum of all digits workhow to find sum of digits of the integer n when written in base b program to find sum of digits of a numbercompute the sum of all digits in n that are 6 or 7you are given a two digit integer n return the sum of its digits examplegiven length and sum of digits to find the sum of digits of a number and its equivalentfind the sum of all the 4 digit numbers that can be formed with the digits 2 2c 3 2c 4 and 5 3fsum of digits in a numbercalculate the summation of digits of a number take a number n form user and calculate the sum of the digits of that number calculate sum of integers up to integersum of digits in a single digitsum of digit in integersum the number of integers in your asmid till you get a single digitprogram to sum of digits of a numberhow to find digits of sum is givensummation of its digits how to sum digits of a number insum of digits sequencefind the sum of all 4 digit numbers formed by taking all the digits 2 2c 4 2c 6 and 8 22find the sum of all the 4 digit numbers that can be formed with the digits 3 2c 4 2c 4 and 2 program to find the sum of digits of a numbeyou are given a two digit integer n return the sum of its digits sum of digits sum of digits in a number in o 281 29given the length and sum of digitsnumber of numbers with given sum of digitsgiven a number n 2c find the sum of all the digits of the numberprogram for sum of the digits of a given numbergiven a five digit integer 2c print the sum of its digits sum of all digits in a numberreturn the sum of its digits number whose sum of its digits is the number itselfhow to get the sum of a digituser enter an integer of 6 digits then calculate the sum of onecount total digits in a numberthe sum of all the possible numbers of 4 digits formed by digits 3 2c 5 2c 5 2c and 6 using each digit once is find sum of int digitf 28n 2cb 29 be the sum of digits of the integer n when written in base b formula for sum of digitssum the digits of an integer