Need some help with this c++ recursive function: Write the function int countEights(int n). Inside the function, compute recursively (no loops) the count of the occurrences of 8 as a digit inside the parameter n. Except that an 8 with another 8 immediately to its left counts double, so 8818 yields 4. Note that mod (%) by 10 yields the rightmost digit (126 % 10 is 6), while divide (/) by 10 removes the rightmost digit (126 / 10 is 12). Here are some examples: countEights(8) returns 1 countEights(818 returns 2 countEights(8818) returns 4

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 8SA
icon
Related questions
Question

Need some help with this c++ recursive function:

Write the function int countEights(int n). Inside the function, compute recursively (no loops) the count of the occurrences of 8 as a digit inside the parameter nExcept that an 8 with another 8 immediately to its left counts double, so 8818 yields 4.

Note that mod (%) by 10 yields the rightmost digit (126 % 10 is 6), while divide (/) by 10 removes the rightmost digit (126 / 10 is 12).

Here are some examples:

  • countEights(8) returns 1
  • countEights(818 returns 2
  • countEights(8818) returns 4
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Fibonacci algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning