Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a recursive function, sumDigits, that takes an integer as a parameter and returns the sum of the digits of the integer. please use the

Write a recursive function, sumDigits, that takes an integer as a parameter and returns the sum of the digits of the integer.

please use the templates below to make the program. ( C++ )

functions.cpp

#include

using namespace std;

inline void sumDigits(long long& sum, long long num) { //checkign base condtion here

if(num == 0)

return ;

else

{ //adding the last digit to the sum

sum += num%10;

num /= 10; //removing the last digit from num

sumDigits(sum, num); //calling recursively

}

______________________________________________________________________

main.cpp

#include #include "functions.cpp"

using namespace std;

int main() { long long num = 930567829100185; long long sum = 0;

sumDigits(sum, num);

cout << "The sum of the digits of " << num << " is: " << sum << endl;

return 0; }

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

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago