C++ programming Write the body of a function with the following signature. bool
ID: 3910987 • Letter: C
Question
C++ programming
Write the body of a function with the following signature. bool divisible_9(int n, int &s); • You are given an input positive integer n > 0. • The decimal digits of n are x1x2x3 . . . . • The sum of the digits s = x1 + x2 + . . . . • If s ? 9 then return true if s == 9, else return false. • If s > 9 then set n = s and call the function recursively until you obtain s ? 9. 1. For example if n = 999 then proceed recursively until you obtain s = 9 and return true. 2. For example if n = 9876 then proceed recursively until you obtain s = 3 and return false. • If you do your work correctly, the function will return true if n is divisible by 9 (and the output will be s = 9) and false if not (and the output will be a value 1 ? s ? 8). • Apply your function to your student id and state the output
Explanation / Answer
bool divisible_9(int n, int &s) { s = 0; while(n > 0) { s += n % 10; n /= 10; } if(sRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.