Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions