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
iogann1982 [59]
3 years ago
6

The maximum-valued element of an integer-valued array can be recursively calculated as follows: If the array has a single elemen

t, that is its maximum (note that a zero-sized array has no maximum) Otherwise, compare the first element with the maximum of the rest of the array-- whichever is larger is the maximum value. Write an int function named max that accepts an integer array, and the number of elements in the array and returns the largest value in the array. Assume the array has at least one element.
Computers and Technology
1 answer:
Tasya [4]3 years ago
4 0

Solution :

#include <iostream>

using namespace std;

//Function Declaration

int max(int arr[],int size);

int main()

{

//Declaring variable

int size;

 

while(true)

{

cout<<"Enter the no of elements in the array :";

cin>>size;

if(size<=0)

{

  cout<<"Invalid.Must be greaterthan Zero"<<endl;

  continue;

  }

  else

  break;

  }

 

//Creating an array

int arr[size];

/* getting the inputs entered by

* the user and populate them into array

*/

for(int i=0;i<size;i++)

{

cout<<"Enter element#"<<i+1<<":";

cin>>arr[i];

}

//calling function

int maximum=max(arr,size);

//Displaying the output

cout<<"The maximum Element in the Array is :"<<maximum<<endl;

return 0;

}

/* Function implementation which finds

* the maximum element in the array and return it

*/

int max(int arr[],int size)

{

//Declaring the static variables

static int k=0,maximum=-999;

 

/* This if block will execute only if the value of k

* is less than the size of an array

*/

if(k==size-1)

{

   return arr[0];

  }

else if(size-1>k)

{

if(arr[k]>maximum)

maximum=arr[k];

 

//Incrementing the k value

k++;

 

//Calling the function

max(arr,size);

}

return maximum;

}

You might be interested in
Select the correct answer from each drop-down menu. Which IF formulas are valid? _____ and _____ are valid IF formulas.
Lyrx [107]

Answer:

=IF(D3>50; E3; F3) AND =IF(A1>60;"Pass";"Fail")

Explanation:

An IF structure is built following this pattern:

IF(TEST;IFTRUE;IFFALSE)

These are the only options in the given drop-down menus what comply with this pattern.  All others are not following this pattern.

The computer will do the test and if the result is true will apply the IFTRUE value, otherwise will apply the IFFALSE value.

4 0
4 years ago
You are asked to write a program that will display a letter that corresponds with a numeric rating system. The program should us
Mice21 [21]

Answer:

rate

Explanation:

6 0
3 years ago
While a threat intelligence analyst was researching an indicator of compromise on a search engine, the web proxy generated an al
inna [77]

Answer: the corret answer C. The analyst has prefetch enabled on the browser in use.

Explanation:

The analyst has like an indicator which is prefetch enabled on the browser in use.

7 0
3 years ago
5. The problem domain refers to the
solong [7]

Answer:

The problem domain refers to the support options.

6 0
3 years ago
Sql is an example of a ________ category programming language. 4gl 3gl 5gl 2gl
kicyunya [14]
The answer is Fourth-generation language (4GL).  <span>Sql is an example of a 4GL category programming language.  </span>SQL<span> is considered a Fourth-generation </span>language<span> (</span>4GL), whereas Java and C++ are third-generation languages<span> (3GLs). Fourth-generation </span>languages<span> are programming  </span>languages<span> that are closer to human </span>language<span> than the high-level </span>languages<span>  like Java.</span>
8 0
3 years ago
Other questions:
  • This stores a piece of data and gives it a specific name
    7·1 answer
  • When was kale discovered?
    9·1 answer
  • Which type of fiber-optic connector, containing one fiber-optic strand per connector, is connected by pushing the connector into
    7·1 answer
  • What do you think is the most fascinating aspect of the internet?
    7·2 answers
  • Donna often travels around the world. When she travels, she needs to access her emails from different locations. However, to kee
    6·2 answers
  • The illustration shows different types of text language.
    5·2 answers
  • Did it surprise you to discover that the Sun is actually a star in the middle of its life cycle? Why or why not?
    8·1 answer
  • Is jesus dead or alive
    11·1 answer
  • Which quality should an experiment have to be replicable and valid? O clearly detailed results O a well-cited research paper O s
    7·1 answer
  • A successful entrepreneur is
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!