answersLogoWhite

0

#include<iostream>

unsigned sum_of_digits(unsigned num)

{

unsigned sum = 0;

do

{

sum += num%10;

} while(num/=10);

return sum

}

int main()

{

unsigned num = 42;

unsigned sum = sum_of_digits (num);

std::cout << sum; // output: 6

}

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

How do you find the common ratio of 2 plus 4 plus 6 plus 8 plus 10.. is this valid?

No, there is no common ratio for the given number.


What is the answer to 1245343 plus 823729849287498274982739487298472983749287498237498273948287518239108?

The answer is identical to the given long number that starts with "8237.....", until the last 7 digits.Change the last 7 digits from ".....8239108" to ".....9484451".


How many digits are there in a phone number in Russia?

Telephone numbers throughout Russia are uniformly 3 digits for the area code plus 7 digits for the local number.


What is the Aram strong number in c plus plus?

If the sum of squares of digits of a number equals to the number itself, then that number is called an aram strong number.


What is 87587847587348978578 plus 8?

8.75878476e19=================================Another contributor increased the precision of the answer:The sum is the same number given in the question,with the last two digits being 86 instead of 78 .


What number is this plus 88213300237?

The first two digits indicate it's a number for either Taiwan or Bangladesh.


The smallest two digits number plus the biggest two digits number is?

The smallest two digit number is 00 (a number used as a wire gauge) and the biggest is 99, so the sum of the biggest and smallest 2-digits numbers is 99 (99 + 00).


How do you find the mass number given the proton electrons and atomic number but not the neutrons?

The mass number of an atom is the number of protons plus the number of neutrons. This is is the same as the number of electrons plus the number of neutrons since the number of protons is the same as the number of electrons in an atom.


What is the maximum number represents by 16 bit signed binary digits?

Plus or minus 65,535


Where is this phone from plus 494142907529?

The first two digits (49) suggest a number in Germany. HOWEVER - there is no area code starting with the next three digits (414),


If 5 plus 3 equals 1628 and 9 plus 1 equals 80810 and 8 plus 6 equals 28214 AND 5 plus 4 equals 919 then 7 plus 2 equals?

the answer is 4559 the one's digit is the sum of given two numbers here it is 9 the other three digits are determined by taking the difference of the two numbers here it is 5 the difference will be the next digit so the number becomes 59 then multiply the sum with the difference 9*5=45 that will be the next digits so the number is4559


The reciprocal of a number plus the reciprocal of twice the number equalsone half Find the number?

The reciprocal of a number plus the reciprocal of twice the number equals Find the number. 1/2 find the number