1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
attashe74 [19]
3 years ago
8

Write two recursive versions of the function minInArray. The function will be given a sequence of elements and should return the

minimum value in that sequence. The two versions differ from one another in the technique we use to pass the sequence to the function. In version 1 – The prototype of the function should be: int minInArray1(int arr[], int arrSize) Here, the function is given arr, an array of integers, and its logical size, arrSize. The function should find the minimum value out of all the elements in positions: 0, 1, 2, …, arrSize-1. In version 2 – The prototype of the function should be: int minInArray2(int arr[], int low, int high) Here, the function is given arr, an array of integers, and two additional indices: low and high (low ≤ high), which indicate the range of indices that need to be considered. The function should find the minimum value out of all the elements in positions:
Computers and Technology
1 answer:
Tomtit [17]3 years ago
3 0

Answer:

Following are the code to this question:

#include <iostream>//defining header file

using namespace std;//using namespace

int minInArray1(int arr[],int arrSize)//declaring method minInArray1

{

if(arrSize == 1)//use if block to check arrSize value is equal to 1  

{

return arr[0];//return first element of array

}

else //defining else block

{

int max= minInArray1(arr, arrSize-1);//use integer variable max to call method recursively  

if(arr[arrSize-1] < max)//use if block to check array value  

{

max = arr[arrSize-1];//use max to hold array value

}

return max;//return max variable value

}

}

int minInArray2(int arr[], int low, int high)//defining a method minInArray2  

{

if(low == high) //use if to check low and high variable value are equal

{

return arr[low];//return low variable value

}

else //defining else block

{

int minimum = minInArray2(arr, low+1, high);//defining integer variable minimum to call method minInArray2 recursively

if(arr[low] < minimum)

{

minimum = arr[low];//use minimum variable to hold array value

}

return minimum;//return minimum value

}

}

int main()//defining main method

{

int arr[10] = { 9, -2, 14, 12, 3, 6, 2, 1, -9, 15 };//defining an array arr

int r1, r2, r3, r4;//defining integer variable

r1 = minInArray1(arr, 10);//use r1 variable to call minInArray1 and hold its return value

r2 = minInArray2(arr, 0, 9);//use r1 variable to call minInArray2 and hold its return value

cout << r1 << " " << r2 << endl; //use print method to print r1 and r2 variable value

r3 = minInArray2(arr, 2, 5);//use r3 variable to call minInArray1 and hold its return value

r4 = minInArray1(arr + 2, 4); //use r4 variable to call minInArray2 and hold its return value

cout<<r3<< " " <<r4<<endl; //use print method to print r3 and r4 variable value

return 0;

}

Output:

please find the attached file.

Explanation:

In the given code two methods, "minInArray1 and minInArray2" is defined,  in the "minInArray1" it accepts two-variable "array and arrSize" as the parameter, and in the "minInArray2" method it accepts three integer variable "array, low, and high" as the parameter.

  • In the "minInArray1" method, and if the block it checks array size value equal to 1 if the condition is true it will return the first element of the array, and in the else block the max variable is defined, that calling method recursively
  • and store its value.
  • In the "minInArray2" method, an if the block it checks low and high variable value is equal. if the condition is true it will return a low array value. In the next step, the minimum value is defined, which checks the element of the array and uses a low array to store its value.
  • In the main method an array and four integer variable "r1, r2, r3, and r4" is defined, which calls two methods "minInArray1 and minInArray2" and use print method to print its value.
You might be interested in
If you want to wrap text so that it fits a particular cell size, which formatting section would you use?
Pavlova-9 [17]

You would use the formatting section of alignment.

7 0
3 years ago
Read 2 more answers
The superintendent forbade the students to bring their books and copies in the exam hall. (into direct speech)​
nata0808 [166]

Answer:

in direct speech, we convey the message of the speaker in his own actual words without any change to another person.

Explanation:

7 0
4 years ago
ITS MAKING ME TYPE URL CODES NOW!
Oxana [17]

Answer:

You have to the [] and it should work.

Explanation:

Hope this helped!!

6 0
3 years ago
Select the layer of the OSI model that is responsible for reformatting, compressing, and/or encrypting data in a way that the ap
Nutka1998 [239]

Answer:Presentation layer

Explanation: Presentation layer is the sixth layer belonging to the OSI model . It has the functionality of presenting the data or information in a standard and formatted way.The syntax is usually error free , well defined and adequate and thus also called as syntax layer. Presentation layer works between the application layer and the network layer.

It also performs the services of compression, encryption, decryption etc.

4 0
3 years ago
What is fair use?
koban [17]

Answer:

I believe its C

Explanation:

I'm sorry if its wrong...

8 0
4 years ago
Read 2 more answers
Other questions:
  • Complete main() to read dates from input, one date per line. Each date's format must be as follows: March 1, 1990. Any date not
    9·1 answer
  • You grant them remote access to your computer to enable them to act as you to fix the situation. what type of os must be install
    9·1 answer
  • Jamie works on a spread sheet in which he has to label stes of data. How can he navigate between the cells in the spread sheet
    8·1 answer
  • When you insert an object in a document, Word always inserts it as a floating object. true or false
    14·1 answer
  • when a page contains function is loaded the browser by passes the function without running it - true or false
    7·1 answer
  • What is the different between 32bit anf 64 bit verision​
    11·1 answer
  • Which part of the Word application window should the user go to for the following activities?
    14·1 answer
  • Plz help
    8·1 answer
  • Which of these is an example of output?
    13·2 answers
  • A(n) ________ portal offers a personalized, single point of access through a web browser to employees located inside and outside
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!