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
Which can be inserted using the insert panel in dreamweaver cc?
timofeeve [1]

Answer: Learn how to use the Insert panel in Dreamweaver to create and insert objects, such as tables, images, OAM files, and Bootstrap components. The Insert panel contains buttons for creating and inserting objects such as tables and images. The buttons are organized into categories.

3 0
3 years ago
Explain the difference between file and folder (in your own words)
denpristay [2]

Answer:

the difference is one is online and one is not

Explanation:

A file is usually what you find online. And a folder is what you put papers into.

7 0
3 years ago
How do i work this out? does anyone do programming?
Pavlova-9 [17]
Answer : No sorry ..
6 0
3 years ago
How do you do this question?
laila [671]

Answer:

(a) 1 to 8

(b) 1 to 6

Explanation:

A "leaf" is a node at the end of a binary tree (in other words, it has no "children").  All other nodes are "non-leaf" nodes.

The smallest number of leaves is 1.  That would be a binary tree that's just a straight line; each node will have only 1 child, until you get to the last node (the leaf).

To find the largest number of leaves, we start drawing a full binary tree.  A complete tree with 15 nodes has 7 non-leaf nodes and 8 leaf nodes.  A full tree with 6 non-leaf nodes can have up to 6 leaf nodes.

6 0
3 years ago
Read 2 more answers
Grade Co... ▶ Da'yana Stover - Aerospace Engineering.pdf
SVEN [57.7K]
The answer is Space shuttle.
8 0
1 year ago
Read 2 more answers
Other questions:
  • *FREE POINTS* If you comment and follow me this will give up lot of points :p seriously I will follow u back if u do it :p​
    11·2 answers
  • If a user has just added a simple triangle shape into a diagram, how can the triangle be adjusted? Check all that apply. by maki
    6·2 answers
  • What are the basic tools for coding HTML manually?
    10·2 answers
  • In Java, it is possible to create an infinite loop out of while and do loops, but not for-loops. true or false
    11·1 answer
  • What is top down design? a. Top down design is a way of designing your program by starting with the biggest problem and breaking
    7·1 answer
  • Create an application for a library and name it FineForOverdueBooks. TheMain() method asks the user to input the number of books
    7·1 answer
  • Does Buzz or APEX shows all your due assignments on the left of the main home screen?
    11·1 answer
  • A data table is a range that displays what?
    15·2 answers
  • You should always keep a backup of data stored in the cloud because the cloud provider does not automatically do this True or fa
    9·1 answer
  • You've just finished installing a wireless access point for a client. What should you do to prevent unauthorized users from usin
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!