Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
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 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
Expert Solution
arrow_forward
Step 1
The C++ code is given below with code and output screenshot
Happy to help you ?
Step by stepSolved in 4 steps with 2 images
Knowledge Booster
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
- Write a recursive C++ program to find the GCD of two numbers and using this write a function to find the L.C.M of two numbers in O(1) time. GCD function should contain one line of code. Please answer only if you can fulfill the conditions else I will downvote.arrow_forwardcode in python program please Write a function that takes one integer parameter, makes sure it is an integer, prints sum of every two digits and return the sum of digits from the number entered by the user up to 1, using recursion.Sample input: 4 Sample output: 4+3 = 77+2 = 99+1 = 10arrow_forwardWrite a C++ recursive function int fib(int n) that returns the value of the n’th Fibonaccinumber . Do not use a loop. Test it in the main program, not in the function.The Fibonacci sequence is0 1 1 2 3 5 8 13 21…Each Fibonacci number is the sum of the preceding two Fibonacci numbers.arrow_forward
- is it correct ? Write a recursive function that returns the nth number in a fibonacci sequence when n is passed to function. The fibonacci sequence is like 0,1,1,2,3,5,8,13...... Answer: #include <iostream> using namespace std; int getFibonacci(int n) { if (n == 0 || n == 1) return n; else return getFibonacci(n - 1) + getFibonacci(n - 2); } int main() { int n = 7; int result = getFibonacci(n); cout << result; }arrow_forwardWrite code to complete raise_to_power(). Note: This example is for practicing recursion; a non-recursive function, or using the built-in function math.pow(), would be more common.Sample output with inputs: 4 24^2 = 16 def raise_to_power(base_val, exponent_val): if exponent_val == 0: result_val = 1 else: result_val = base_val * ''' Your solution goes here ''' return result_val user_base = int(input())user_exponent = int(input()) print('{}^{} = {}'.format(user_base, user_exponent, raise_to_power(user_base, user_exponent)))arrow_forwardjava netbeans ______ What is wrong with the following code? And correct the error. int[] array1= {10,20,30}; int result = 0; for(int i=0 ;i<= array1.length;i++) result *= array1[i];arrow_forward
- Need some help with this c++ problem In order to compute a power of two, you can take the next-lower power and double it. For example, if you want to compute 211 and you know that 210 = 1024, then 211 = 2 × 1024 = 2048. Based on this observation, write a recursive function int pow2(int n) where n is the exponent. If the exponent is negative, return -1. int pow2(int n) { ..... }arrow_forwardin c++arrow_forwardUsing recursion, write a function sum that takes a single argument n and computes the sum of all integers between 0 and n inclusive. Do not write this function using a while or for loop. Assume n is non-negative. def sum(n): """Using recursion, computes the sum of all integers between 1 and n, inclusive. Assume n is positive. >>> sum(1) 1 >>> sum(5) # 1 + 2 + 3+ 4+ 5 15 "*** YOUR CODE HERE ***"arrow_forward
- Please solve this in C programming language as early as possible. .Write a recursive function that can use to add all the numbers from 5 to n, where n>5. n will be given by the user. Prototype: int add_num(int n);arrow_forwardin c++ with pre and post pseudocode please dont show me the same code from others please thank u Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which Takes an array of integers and its size as input params and returns a bool such that 'true' ==> all elements of the array are prime, so the array is prime, 'false' ==> at least one element in array is not prime, so array is not prime. Print out a message "Entering <function_name>" as the first executed statement of each function. Perform the code to test whether every element of the array is a Prime number. Print out a message "Leaving <function_name>" as the last executed statement before returning from the function. Remember - there will be nested loops for the iterative function and there can be no loops at all in the recursive function.…arrow_forwardPython: How do I create a recursive function asterisk with both recursive and base cases? so for n=3, you would have below; *** ** * code that I have: for i in range(n): print("*",end="")arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education