Can someone show me how to write a recursive function that count how many time the number 7 occur in an integer. Thanks
qvyhnl
0
Light Poster
Recommended Answers
Jump to PostYes I can. But instead of giving you the answer. I am going to help and guide you through this long and tough journey to find the number of magical sevens in a given integer.
So to start, do you have any ideas? Does not have to be in …
Jump to PostYour attempt is close. You need to change line 3. Also line 4 can be reduced to simply
if(n % 10 == 7) return 1 + count7(n/10)
Line 3 is going to be your base case. When should you stop in ALL cases? For example in you base case if …
All 7 Replies
mrnutty
761
Senior Poster
qvyhnl
0
Light Poster
mrnutty
761
Senior Poster
qvyhnl
0
Light Poster
mrnutty
761
Senior Poster
qvyhnl
0
Light Poster
mrnutty
761
Senior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.