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
Art [367]
4 years ago
15

unsigned int SumOfDigits(unsigned int n)Description: Develop a function that takes a non-negative integer n as a parameter and r

eturns a non-negative integer containing the sum of n’s digits. For example, if the input parameter n was 17239 then the output of this function should be 1 + 7 + 2 + 3 + 9 = 22
Engineering
1 answer:
Verdich [7]4 years ago
7 0

Answer:

The solution code is written in C++.

  1. unsigned int SumOfDigits(int n){
  2.    int sum = 0;
  3.    sum += n % 10;
  4.    n = n / 10;
  5.    
  6.    while(n != 0){
  7.        sum += n % 10;
  8.        n = n / 10;
  9.    }
  10.    
  11.    return sum;
  12. }

Explanation:

Firstly, define a function with name <em>SumOfDigits()</em> that take one input integer, <em>n</em> and return an unsigned summation integer (Line 1). Next, we declare a variable sum to hold the value of summation of all the integer digits. Let's initialize it with zero (Line 2).

We can get the first digit from the integer by calculating the remainder of n after dividing it by 10 using modulus operator (%) and the remainder obtained is added to the sum variable (Line 3). Next, we divide the integer n by 10 (Line 4). This will discard the last digit of integer n (from the right).

We just need to repeat the process from Line 3-4 using a while loop so long as the current integer n is not zero (Line 6-8). We shall be able to take out the individual digit and add it to variable<em> sum</em>.  

At the end, return the <em>sum</em> as output (Line 11).

You might be interested in
Speed limit signs are classified as
luda_lava [24]

Answer:

B. Regulatory signs

Explanation:

traffic rules

5 0
3 years ago
Read 2 more answers
All of these are true about steel EXCEPT that:
natta225 [31]

Answer:B) heat tends to strengthen high-strength steel.

Explanation: You are right it is B

3 0
2 years ago
As a construction manager, Alex found a major issue with the client's design demands. He found out that the building design was
kipiarov [429]

Answer:

Which human resource skill helped Alex convince the client? its nagotiation

Explanation:

got it right on the test.

6 0
3 years ago
Cell phones require powerful batteries in orde to work effectively. Which activity is best described as an engineering endeavor
natta225 [31]
Where are the options?
8 0
3 years ago
Some designers suggest that speech recognition should be used in a telephone menu system. This would allow users to interact wit
Ghella [55]

The designers suggest that speech recognition allows for spoken interaction or conversation and spoken prompts or commands.

Explanation:

The speech recognition is used when the user has physical impairments and hands are busy, eyes are occupied and the user cannot read.

We can save time with the usage of speech recognition system. The users are knowledgeable based on the actions available.

The problems faced in speech recognition system are in the noisy environment it has bad microphones and the commands should be learned and remembered.

The other obstacle is error correction is time consuming. the speech production has slow space to speech output provides privacy in public spaces. The disadvantage is it contains large amount of information.

5 0
4 years ago
Other questions:
  • What is the product of current and Resistance A power B voltage inductance D conductance
    10·1 answer
  • The hull of a vessel develops a leak and takes on water at a rate of 57.5 gal/min. When the leak is discovered the lower deck is
    9·1 answer
  • Describe what a dislocation is, and how it is important in the plastic deformation of materials
    14·1 answer
  • At steady state, a valve and steam turbine operate in series. The steam flowing through the valve undergoes a throttling process
    9·1 answer
  • A rectangular conductor with a cross sectional area of 1.04 square millimeters (mm) ^2 has a resistance of 0.075 ohms. What woul
    8·1 answer
  • By saying that the electrostatic field is conservative, we do not mean that:_______ The potential difference between any two poi
    5·1 answer
  • Race cars at the Indianapolis Speedway average speeds of 185 mi/h. After determining the altitude of Indianapolis, find the Mach
    8·1 answer
  • Does any1 know TERMS OF MEASUREMENT
    12·2 answers
  • What is the best way to collaborate with your team when publishing Instagram Stories from Hootsuite?
    14·1 answer
  • Okay<br>going offline bye<br>have a great day​
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!