1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Oksi-84 [34.3K]
3 years ago
5

Write a recursive method named digitSum that accepts an integer as a parameter and returns the sum of its digits. For example, c

alling digitSum(1729) should return 1 7 2 9, which is 19. If the number is negative, return the negation of the value. For example, calling digitSum(-1729) should return -19.
Computers and Technology
1 answer:
harkovskaia [24]3 years ago
4 0

Answer:

The function in Python is as follows:

def digitSum( n ):

if n == 0:

 return 0

if n>0:

    return (n % 10 + digitSum(int(n / 10)))

else:

    return -1 * (abs(n) % 10 + digitSum(int(abs(n) / 10)))

Explanation:

This defines the method

def digitSum( n ):

This returns 0 if the number is 0

<em> if n == 0: </em>

<em>  return 0 </em>

If the number is greater than 0, this recursively sum up the digits

<em> if n>0: </em>

<em>     return (n % 10 + digitSum(int(n / 10))) </em>

If the number is lesser than 0, this recursively sum up the absolute value of the digits (i.e. the positive equivalent). The result is then negated

<em> else: </em>

<em>     return -1 * (abs(n) % 10 + digitSum(int(abs(n) / 10)))</em>

You might be interested in
Which is a software configuration management concept that helps us to control change without seriously impeding justifiable chan
Darina [25.2K]

Answer:

Baselines

Explanation:

The idea of software configuration management is that of monitoring and controlling changes in the software. The baseline is the standard and formally accepted form of a software item that is meant to be configured. It is like a generally accepted reference point, which could be applied in effecting incremental changes in the software.

There are three types of baselines which are the functional, developmental, and product baselines. Functional baselines provide an overview of the functionality and specifications of a system. The product baseline encompasses both the functional and physical details of the system.

7 0
4 years ago
Write a function called calculate() that accepts three integer Numbers as arguments, compute these values : Sum and Product and
Dmitrij [34]

Answer:

int* calculate(int a,int b,int c){

   int result[] = {0,0};

   int sum = a+b+c;

   int product = a*b*c;

   result[0] = sum;

   result[1] = product;

   return result;

}

Explanation:

The function is a block of the statement which performs the special task.

The function can return one integer, not more than one integer.

If we want to return multiple values then, we can use array.

we store the result in the array and return that array to the main function.

This is the only possible way to return multiple values.

So, define the function with return type array and declare the array with zero value.

Then, calculate the values and store in the variable after that, assign to the array.

Finally, return that array.  

5 0
3 years ago
How do productivity programs most benefit the way we work and live?
Bad White [126]

Answer:

THEY MAKE US LESS TOLERANT OF WAITING AND WORKING

6 0
3 years ago
Read 2 more answers
3k means about 3 thousand bytes. how would you express two hundred million bytes? .
barxatty [35]
200,000,000 bytes

200,000KB

200MB

0.2GB

etc, etc.
7 0
4 years ago
David has created a lot of styles and now his Quick Style Gallery contains styles he no longer uses.
shusha [124]

Answer:

Right-click the style in the Quick Styles Gallery, and select the Remove from Quick Style Gallery option.

Explanation:

3 0
4 years ago
Other questions:
  • The __________ endian storage format places the __________ byte of a word in the lowest memory address. The __________ endian st
    15·1 answer
  • PLEASE FILL IN THE BLANK FOR THESE POINTS!!!!!
    15·2 answers
  • Which features can Danica use to fix the issue
    5·1 answer
  • Usually, the same software that is used to construct and populate the database, that is, the DBMS, is also used to present ____.
    11·1 answer
  • What is not true of credit scores?
    11·1 answer
  • In what way was the Ohio River Valley a factor in the French and Indian War? The Ohio River Valley was controlled by both France
    8·2 answers
  • What Information Technology is Walt Thomas responsible for?
    13·2 answers
  • If you created a variable called name, what data type would that value be?
    7·2 answers
  • Can you help me in this question
    13·1 answer
  • PLEASE HURRY!!!!<br> Look at the image below
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!