Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a recursive function int count_digit(int digit, int numb) that returns the number of occurrences of digit in the decimal representation of numb. digit is

Write a recursive function

int count_digit(int digit, int numb)

that returns the number of occurrences of digit in the decimal representation of numb. digit is an int between zero and nine inclusive. For example, the call count_digit(8, 18488) should return 3, because there are three eights in the decimal representation of 18488. Recall that if num is an integer, then num/10 is the integer part of num divided by ten, while num%10 is the remainder of num divided by ten. These provide a way to split the problem into smaller pieces. All looping in your function must be accomplished with recursion---you may not use any of iteration constructs. You may use a helper function if you like, but none is necessary.

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

More Books

Students also viewed these Databases questions