Question: Please do this as simple as possible and give explanations. Hoping to have this with zero error. PROGRAM LANGUAGE IS C++ 2. Write a program

Please do this as simple as possible and give explanations. Hoping to have this with zero error. PROGRAM LANGUAGE IS C++

2. Write a program that will ask the user to enter any integer, and store that in a suitable variable, say N. Now write a function SumDigits that takes N as input and the function returns the sum of all the digits N contains. Call this function from main, and display the answer. The function SumDigits need to follow the algorithm given as below:

Declare sum and initialize to 0

Write a while loop using the condition that as long as N > 0, do the following:

sum = sum + N % 10

N = N/10

Return the sum

Test this program by entering (a) any 4, (b) 5 and (c) 6 digit integer as input, and each case copy the output and paste it below your program using block comment statements.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!