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 the array. Demonstrate the method in a program.
3. String Reverse
Write a recursive method that accepts a string as its argument and prints the string in reverse order. Demonstrate the method in a program.
4. maxElement Method
Write a method named maxElement, which returns the largest value in an array that is passed as an argument. The method should use recursion to find the largest element. Demonstrate the method in a program.
5. Recursive Power Method
Write a method that uses recursion to raise a number to a power. The method should accept two arguments: the number to be raised and the exponent. Assume that the exponent is a nonnegative integer. Demonstrate the method in a program.
6. Sum of Numbers
Write a method that accepts an integer argument and returns the sum of all the integers from 1 up to the number passed as an argument. For example, if 50 is passed as an argument, the method will return the sum of 1, 2, 3, 4, . . . 50. Use recursion to calculate the sum. Demonstrate the method in a program.
HI, I have implemented first functions.
Please repost others in separate post.
Please let me know in case of any issue in first 3.
public class RecursiveFunctions {
public static int recursivemultiplication(int x, int y){
// making y positive
if(y < 0)
return recursivemultiplication(-x, -y);
// base case
if(y == 0)
return 0;
// recursive case
return x + recursivemultiplication(x, y-1);
}
public static boolean reFinding(int arr[], int start, int key){
// base case
if(start >= arr.length)
return false;
if(arr[start] == key)
return true;
return reFinding(arr, start+1, key);
}
public static void reString(String s, int index){
if(index < 0)
return;
System.out.print(s.charAt(index));
reString(s, index-1);
}
public static void main(String[] args) {
System.out.println("5*7 : "+recursivemultiplication(5, 7));
int arr[] = {55,3,12,65,22,9};
System.out.println("22 is avaiulable ? "+reFinding(arr, 0, 22));
String s = "pk this is";
reString(s , s.length()-1);
}
}
/*
Sample run:
5*7 : 35
22 is avaiulable ? true
si siht kp
*/
Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters...
c++ Write a function that uses recursion to 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 nonnegative integer. Demonstrate the function in a program. Write a function that accepts an integer argument and returns the sum of all the integers from 1 up to the number passed as an argument. For example, if 50 is passed as an argument, the function will...
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...
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...
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...
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
Sum of Numbers Problem: Write a method that accepts an integer argument and returns the sum of all the integers from 1 up to the number passed as an argument. For example, if 50 is passed as an argument, the method will return the sum of 1, 2, 3, 4, . . . 50. Use recursion to calculate the sum. Demonstrate the method in a program. The program should be called SumOfNumbers.java.
I need help writing this program in C++. Thanks so much for your help in advance Function 1: Write a function that accepts an integer argument and returns the sum of all the integers from 1 up to the number passed as an argument. For example, if 50 is passed as an argument, the function will return the sum of 1, 2, 3, 4, ... 50. Use recursion to calculate the sum. Demonstrate the function in a program. A sample...
(C++)Write a function that accepts an int array and the array’s size as arguments.The function should create a new array that is twice the size of the argument array.The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0.The function should return a pointer to the new array.Demonstrate the function by using it in a main program that reads an integer N (that is not more...
9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in the main program that reads an integer N (that is not more than 50) from standard input and then reads N integers from a file named...
To be written in C++ write a recursive function that accepts a string object as its argument and prints the string in reverse order. demonstrate the function in a driver program.