Write a recursive function that has an argument that is an array of characters and two arguments that are bounds on array indexes. The function should reverse the order of those entries in the array whose indexes are between the two bounds. For example, if the array is
a[0] == 'A' a[1] == 'B' a[2] == 'C' a[3] == 'D' a[4] == 'E' |
and the bounds are 1 and 4, then after the function is run the array elements should be
a[0] == 'A' a[1] == 'E' a[2] == 'D' a[3] == 'C' a[4] == 'B' |
Embed the function in a
Want to see the full answer?
Check out a sample textbook solutionChapter 14 Solutions
EBK PROBLEM SOLVING WITH C++
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Objects (6th Edition)
Starting Out with C++: Early Objects
Programming in C
Artificial Intelligence: A Modern Approach
Modern Database Management (12th Edition)
Computer Science: An Overview (12th Edition)
- Write a recursive function that, given a sequence of comparable values, returns the count of elements where the current element is less than the following ( next ) element in the given sequence. See the examples given below. def count_ordered ( seq ) : """ Input : A sequence of comparable elements Output : The number of elements that are less than the following element in the sequence Example : >>> count_ordered ( [ 1 , 2 , 3 , 4 , 5 , 6 ] ) 5 >>> count_ordered ( ( 1 , 12, 7.3 , -2,4 ) ) 2 >>> count_ordered ( 'Python' ) 2 >>> count_ordered ( [ 6 ] ) 0 >>> count_ordered ( [ ] ) 0 """ In the first example above , count_ordered ( [ 1,2,3,4,5,6 ] )the returned answer is 5 because for all the first 5 numbers the current number is less than the next number. In the second example above, count_ordered ( ( 1,12,7.3 , -2,4 ) )the…arrow_forwardIN C++ Instructions Write a recursive function to implement the recursive algorithm of Exercise 16 (reversing the elements of an array between two indices). Also, write a program to test your function. Your program should prompt the user for the integers in the array, as well as the low index and then the high index. The instructions from Exercise 16 have been included below for your convenience: Suppose that intArray is an array of integers, and length specifies the number of elements in intArray. Also, suppose that low and high are two integers such that 0 <= low < length, 0 <= high < length, and low < high. That is, low and high are two indices in intArray. Write a recursive definition that reverses the elements in intArray between low and higharrow_forwardIN C Programing Let us define the weighted sum of an integer array a[0], a[1], a[2], …, a[n-1] be a[0]*1 + a[1]*2 + a[2]*3 + …+a[n-1]*n. For example, the weighted sum of the array [5,2,6] would be 5*1+2*2+6*3 = 27. Write a recursive function that takes in an array numbers and its length n, and returns its weighter sum. You can assume n is non-negative integer. int weightedSum(int numbers[], int n) {arrow_forward
- Q#1 Write a recursive function printRev ( int a[ ], int s, int e) that receives an integer array a [ ], a start index s, and an end index e. The function should print the array elements in reverse order. void printRev ( int a[ ], int s, int e); Trace your function given the following array and function call. Draw your steps. int a[ ] = {4, 2, 3, 5};and printRev(a, 0, 3); language c++arrow_forwardWrite a function that accepts two arguments,, an array of integers, and a numberindicating the number of elements in the array. Th e function should recursive lycalculate the sum of all the numbers in the array. Demonstrate the use of the functionin a program that asks the user to enter an array of numbers and prints its sum.arrow_forwardWrite a recursive function recursiveMinimum that takes an integer array, a starting subscript, and an ending subscript as arguments, and returns the smallest element of the array. The function should stop processing and return when the starting sub- script equals the ending subscript. c++arrow_forward
- Instructions Write a recursive function to implement the recursive algorithm of Exercise 16 (reversing the elements of an array between two indices). Also, write a program to test your function. Your program should prompt the user for the integers in the array, as well as the low index and then the high index. The instructions from Exercise 16 have been included below for your convenience: Suppose that intArray is an array of integers, and length specifies the number of elements in intArray. Also, suppose that low and high are two integers such that 0 <= low < length, 0 <= high < length, and low < high. That is, low and high are two indices in intArray. Write a recursive definition that reverses the elements in intArray between low and higharrow_forwardInstructions Write a recursive function to implement the recursive algorithm of Exercise 16 (reversing the elements of an array between two indices). Also, write a program to test your function. Your program should prompt the user for the integers in the array, as well as the low index and then the high index. The instructions from Exercise 16 have been included below for your convenience: Suppose that intArray is an array of integers, and length specifies the number of elements in intArray. Also, suppose that low and high are two integers such that 0 <= low < length, 0 <= high < length, and low < high. That is, low and high are two indices in intArray. Write a recursive definition that reverses the elements in intArray between low and high. Textbook: C++ Programming: From Problem Analysis to Program Design 8th Edition Publisher: Cengage Learning Edition ISBN: 9781337102087arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning