Question: Use recursion to complete the following code. No iterative code allowed! #include using namespace std; int sumDigits(int n); int main() { cout < < sumDigits(1)

Use recursion to complete the following code. No iterative code allowed!

#include using namespace std; int sumDigits(int n); int main() { cout << sumDigits(1) << endl; // Should print 1 cout << sumDigits(123) << endl; // Should print 6 cout << sumDigits(57496) << endl; // Should print 31 cout << sumDigits(777) << endl; // Should print 21 return 0; } int sumDigits(int n) { // Your recursive code here - }

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!