(I'm assuming base 10 math) You could cheat. Convert the number to a string with no leading zeros. Capture the left most and right most characters of the string. Convert captured string variables back to integers. Add the integers. (Note: Consider a base string having a string length of 0 or 1.)
// returns the sum of the digits of num
int sumDigits(int num) {
int sum = 0;
int currentDigit;
// four step algorithm:
// step 1: loop until we have no digits left to process
while(num > 0) {
// step 2: find out the rightmost digit
currentDigit = num % 10;
// step 3: add the rightmost digit to our sum
sum += currentDigit;
// step 4: remove the rightmost digit from num
num /= 10;
}
return sum;
}
5
It appears that only single digit numbers work (0 thru 9)
Well, it's very hard to write a flowchart in text, so I'll give you some pseudo code instead. int number = the given number int sum = 0 loop while number is not 0 sum = sum + (number mod 10) number = number / 10
Peterson Number:145 = 1! + 4! + 5!number=sum of (factorials of digits)
# includevoid main(){int no,rem=0,sum=0,n; /*declaration*/printf("Enter 2 digit number:");scanf("%d",&no);for(n=1;n
If the sum of the digits of a given number equals nine or a multiple of nine, nine is a factor of that number.
It is another whole number.
12
82
81
There are several hundred of them. One example, the smallest, is 1039
36
0.1154
43
12
12
The number is 36.