Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 20, Problem 5PC
Program Plan Intro

Recursive Multiplication

Program Plan:

  • Include the required header files.
  • Declare the necessary function prototype and constants.
  • Define the main () function.
    • Call the method “recurmultiplication()” to compute the product of the given element by passing two values as its arguments.
    • The function call gets executed in recursive way to compute the product of the given values.
  • Define the “recurmultiplication()” method,
    • The condition gets validated to check whether the given value is 1 and will return the product by returning the value of “y”.
    • The condition validates the value to be greater than 1, the product value is returned after computing the product of all elements that is present by performing repeated addition.

Blurred answer
Students have asked these similar questions
Recursive Multiplication Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 7×4=4+4+4+4+4+4+4(To keep the function simple, assume that x and y will always hold positive nonzero integers.)
Recursive PrintingDesign a recursive function that accepts an integer argument,n , and prints the numbers 1 up through n .
2. Sum: a recursive function that computes the sum of integers 1, 2, 3, …., n for a given number n. So Sum(6) should return 1 + 2 + 3 + 4 + 5 + 6 , i.e. 21.sum(n) = n + sum(n-1)
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage