answersLogoWhite

0

int SumOfDigit(int a)

{

if(a== 0)

return 0;

return (a%10 + SumOfDigit(a/10));

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

C progrma to find recursive sum of digit of given no without using recursive function?

the function will be int sum_num(int num) { int p = 0, y; y = num; while (y != 0) { p = (y % 10) + p; y = y/10; } return p; } if you can help me with recursive function i would appreciate it Here it is - int SumOfDigits(int input) { int sum = 0; /// Compute the sum while(input > 0) { sum += input %10; input /= 10; /// print value for examination printf(" %d %d\n",sum, input); } return sum; } int RecursiveSumOfDigits(int input) { /// Deal with the simplest case if(input < 10) return input; printf("Recursing on %d\n",input); return RecursiveSumOfDigits(SumOfDigits(input)); }


In java How do you have a method take in an int value and return an int containing sum of the individual digits in the number using a recursive method?

Add the last digit plus the sum of all the previous digits. The base case is that if your integer only has a single digit, just return the value of this digit. You can extract the last digit by taking the remainder of a division by 10 (number % 10), and the remaining digits by doing an integer division by 10.


Where can you enter a sum in excel?

A sum can be entered in any cell on a spreadsheet or by typing it into the formula bar. You can use calculations in lots of ways to do a sum, including the SUM function, the SUBTOTAL function, using Alt and the equals sign and using the Autosum button.A sum can be entered in any cell on a spreadsheet or by typing it into the formula bar. You can use calculations in lots of ways to do a sum, including the SUM function, the SUBTOTAL function, using Alt and the equals sign and using the Autosum button.A sum can be entered in any cell on a spreadsheet or by typing it into the formula bar. You can use calculations in lots of ways to do a sum, including the SUM function, the SUBTOTAL function, using Alt and the equals sign and using the Autosum button.A sum can be entered in any cell on a spreadsheet or by typing it into the formula bar. You can use calculations in lots of ways to do a sum, including the SUM function, the SUBTOTAL function, using Alt and the equals sign and using the Autosum button.A sum can be entered in any cell on a spreadsheet or by typing it into the formula bar. You can use calculations in lots of ways to do a sum, including the SUM function, the SUBTOTAL function, using Alt and the equals sign and using the Autosum button.A sum can be entered in any cell on a spreadsheet or by typing it into the formula bar. You can use calculations in lots of ways to do a sum, including the SUM function, the SUBTOTAL function, using Alt and the equals sign and using the Autosum button.A sum can be entered in any cell on a spreadsheet or by typing it into the formula bar. You can use calculations in lots of ways to do a sum, including the SUM function, the SUBTOTAL function, using Alt and the equals sign and using the Autosum button.A sum can be entered in any cell on a spreadsheet or by typing it into the formula bar. You can use calculations in lots of ways to do a sum, including the SUM function, the SUBTOTAL function, using Alt and the equals sign and using the Autosum button.A sum can be entered in any cell on a spreadsheet or by typing it into the formula bar. You can use calculations in lots of ways to do a sum, including the SUM function, the SUBTOTAL function, using Alt and the equals sign and using the Autosum button.A sum can be entered in any cell on a spreadsheet or by typing it into the formula bar. You can use calculations in lots of ways to do a sum, including the SUM function, the SUBTOTAL function, using Alt and the equals sign and using the Autosum button.A sum can be entered in any cell on a spreadsheet or by typing it into the formula bar. You can use calculations in lots of ways to do a sum, including the SUM function, the SUBTOTAL function, using Alt and the equals sign and using the Autosum button.


Write a recursive function to find sum of even numbers from 2 to 150?

int sum (int from, int to, int step){if (from>to) return 0;else return from + sum (from+step, to, step);}...n = sum (2, 150, 2);


When using the SUBTOTAL function which is the function number for the SUM function?

4


What is the sum of all possible 2 digit number using the digits 3 and 4?

The sum is 154.


Recursive function in c to compute the number of nodes in a binary tree?

int Nodes (Tree *t) { int sum= 0; if (t) { sum+=1; if (t->left) sum += Nodes (t->left); if (t->right) sum += Nodes (t->right); } return sum; }


What are advantages of using the sum function?

It gives you the sum of two or more numbers.


What is the largest three digit number that has a digit sum of 10?

The largest three-digit number with a digit sum of 10 is 910. This can be determined by maximizing the hundreds place first, setting it to 9, and then adjusting the tens and units places to reach a total digit sum of 10. In this case, using 1 for the tens place and 0 for the units place achieves the desired sum.


How do you write a visual basic program to sum the odd number digits of a 12 digit code using division and Mod and while loops?

Function sum_odd_digits(ByVal number As Integer) As Integer Dim digit As Integer sum_odd_digits = 0 While number <> 0 digit = number Mod 10 If digit And 1 Then sum_odd_digits = sum_odd_digits + digit number = number / 10 End While End Function


Why does an addition problem that has a 4 digit addends could have a 5digit sum?

What is the sum of greatest 3-digit 4-digit 5digit


Using four different digits what is the least sum you can get when you add two digit numbers?

2222