Java Program |
import java.util.Scanner; public class RecursiveExponent { public static void main(String[] args) { long base, exp; Scanner kb = new Scanner(System.in); System.out.print("What is the base: "); base = Long.parseLong(kb.nextLine()); System.out.print("What is the exponent: "); exp = Long.parseLong(kb.nextLine()); long result = getResult(base, exp); System.out.println(base + " raised to the power " + exp + " is " + result); } public static long getResult(long base, long exp) { if(exp == 1) return base; else exp--; return base * getResult(base, exp); } } |
OUTPUT
Important Note: As per HOMEWORKLIB RULES we are advised to attempt one question in a single post. Hope you will understand the issue and will not downvote.
RecursiveExponent.java Write a recursive function that accepts two arguments into parameters x and y, and which...
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...
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
PROBLEM: Write a recursive method named Division that takes two integers X and Y returns the result of integer division (i.e., 8 / 3 = 2). Please comment on every line of code. EXISITNG CODE: int Exponentiation(int X, int Y) { if (Y == 0) // base case return 1; else // recursive case return X * Exponentiation(X, Y - 1); //make recursive call } int Multiply(int X, int Y){ if(Y == 0){ return 0; } else{ return X +...
Data structure c++ Write a recursive function, power, that takes two integers x and y as parameters such that x is nonzero and returns x'. You can use the following recursive definition to calculate xy: If y 20, y = 0; 1, power(x,y)= x, ( xx power(x, y-1), If y<0, y>1. power(x, y) = power(x,-y) Also, write a main function to test your function.
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...
In C++, write a recursive function power that takes two positive integers base and n as inputs and computes base to the n power. Example power(3, 2) is 9. Do not use any loops in your program. This is what I got so far but I'm not sure what I'm doing wrong: #include <iostream> using namespace std; int calc(int x, int y); int main() { calc(2, 3); return 0; } int calc() { cout...
Write a MIPSzy subroutine, power, that accepts 2 arguments x and y and computes x^y . You can assume that x and y are both larger than 0. The main program passes the two parameters and receives the return value through the program stack. addi $t0, $zero, 5100 top: lw $t1, 0($t0) beq $t1, $zero, done addi $sp, $sp, -4 sw $t1, 0($sp) addi $t2, $zero,4 addi $sp, $sp, -4 sw $t2, 0($sp) addi $sp, $sp, -4 jal power lw...
ANSWER USING PYTHON Write a recursive function that takes 2 sorted lists as arguments and returns a single, merged sorted list as a result. For example, if the two input lists are [0, 2, 4, 6, 8] and [1, 3, 5, 7, 9], the returned result should be [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]. Remember that you can add lists in Python using the + operator ([0] + [1,2,3] = [0,1,2,3]) and can take slices of...
*In JAVA please* Tasks This lab has two parts: Write a recursive method that converts a decimal number to a different base number system. Print out the results after testing your method on a few different inputs. Task 1 – Recursive Method Create a recursive method that returns a given number converted from base ten to a given other base number system ranging from two to thirty-six. A decimal number, or base ten number, can be expressed in any other...