Question

C++ PLEASE. MAKE SURE CODE WORKS BEFORE SUBMITING ANSWER Create a recursive function that will accept...

C++ PLEASE. MAKE SURE CODE WORKS BEFORE SUBMITING ANSWER

Create a recursive function that will accept 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.

7 * 4 = 4 + 4 + 4 + 4 + 4 + 4 + 4

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

#include <iostream>
using namespace std;
double multiplication(double x,double y) //recursive function to calculate multiplication
{
if(x>0) //if x>0 then the function call itself recursively
{
return (y+multiplication((x-1),y)); //function call itself
}
else
return 0;
}
int main() //main function
{
double x,y,result;
cout<<"Enter two numbers"<<endl;
cin>>x; // take input from user
cin>>y;
result=multiplication(x,y); // call multiplication function to multiply 2 numbers
cout<<"Result = "<<result; //print output
return 0;
}

1 3 { } #include <iostream> 2 using namespace std; double multiplication(double x, double y) //recursive function to calculat

Output:

Enter two numbers 7 4 Result = 28 ... Program finished with exit code 0 Press ENTER to exit console. I

Add a comment
Know the answer?
Add Answer to:
C++ PLEASE. MAKE SURE CODE WORKS BEFORE SUBMITING ANSWER Create a recursive function that will accept...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Recursive Multiplication in Python Design a recursive function that accepts two arguments into the parameters x...

    Recursive Multiplication in Python 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: 6 × 4 = 4 + 4 + 4 + 4 + 4 + 4

  • Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters...

    Using Java: 1. Recursive Multiplication Write 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: 5×6=6+6+6+6+6 2. Recursive findings Write a recursive boolean method named reFinding. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in...

  • Write a python program (recursive.py) that contains a main() function. The main() should test the following...

    Write a python program (recursive.py) that contains a main() function. The main() should test the following functions by calling each one with several different values. Here are the functions: 1) rprint - Recursive Printing: Design a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. 2) rmult - 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...

  • Section 3: Create a Calculator For this problem, please create a "calculator" function that takes two...

    Section 3: Create a Calculator For this problem, please create a "calculator" function that takes two integers and an operator and does the math operation corresponding to the numbers and the operator. For instance, calculate(5,"+", 6) should return 11. Please support the following operators: +- X/^(addition, subtraction, multiplication, division, exponentiation) 1 2 3 function calculate (numi, operator, num2) { // Do the calculation } RUN CODE Parameters Expected Result Actual Result 1,"+", 4 1,"x", 0 20,"7", 5 3,"", 3

  • C++ Create three recursive functions that accomplish the following: Recursive Power Function this function will raise...

    C++ Create three recursive functions that accomplish the following: Recursive Power Function this function will raise a number to a power. The function should accept two arguments, the number to be raised and the exponent. Assume that the exponent is a non-negative integer. String Reverser function that accepts a string object as its argument and prints the string in reverse order. Sum of Numbers this function accepts an integer argument and returns the sum of all the integers from 1...

  • I am creating a recursive function in c++ and have the following code so far. However,...

    I am creating a recursive function in c++ and have the following code so far. However, can you help me fix it so that it doesn't crash when negative numbers are entered. If negative numbers are entered i want to let the user know negative numbers are not accepted and to try again #include <iostream> using namespace std; int multiplication(int x, int y) { int sum = y; //if value of x is 1, then result of x*y will be...

  • Language: Python Function name : findwaldo Parameters : string Returns: int Description: Write a recursive function...

    Language: Python Function name : findwaldo Parameters : string Returns: int Description: Write a recursive function that takes in a string containing some combination of letters, numbers, and spaces, and return the starting index of the first instance of “waldo” contained in that string. If the string does not contain “waldo”, return -1. This function IS case sensitive, so “waldo” is not the same as “WALDO”. Code using string functions such as .index() and .find() that oversimplify the problem will...

  • Write simplistic recursive Java code for Sierpinski I made a psuedo code tell me if anything...

    Write simplistic recursive Java code for Sierpinski I made a psuedo code tell me if anything wrong with it: // x - left edge, y - right edge, z - peak, num - number of times the program is supposed to run public void drawTriangle (int x, int y, int z, int num) maketriangle(x,y,z); //imaginary method to create triangle using coordinates. if (num == 0) { return; } else { int midxy = (y-x)/2; int midxz = (z-x)/2; int midyz...

  • C - Language Create a recursive function to print a multi-digit number vertically. For example, 2378...

    C - Language Create a recursive function to print a multi-digit number vertically. For example, 2378 should be printed as 2 3 7 8 Be sure to test your program with numbers of different length. The recursive function should return an int and take an int as a parameter. The function should have a base case where the parameter is 0 and this should return 0 Define a temp variable using the remainder operator where temp is equal to the...

  • RecursiveExponent.java Write a recursive function that accepts two arguments into parameters x and y, and which...

    RecursiveExponent.java Write a recursive function that accepts two arguments into parameters x and y, and which returns the value of x raised to the power y. Hint: exponentiation is equivalent to performing repetitions of a multiplication. For example, the base 4 raised to the 6th power = 4*4*4 * 4 * 4 * 4 = 4,096. The only file that you need to create is RecursiveExponent.java. Your main method should prompt the user to supply the base and exponent values...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT