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
Write a program that prompts the user for a measurement inmeters and then converts it into miles, feet, and inches.
zubka84 [21]

Answer:

Program for measurement in meters and then converts it into miles, feet, and inches:

#include<iostream.h>

#include<conio.h>

void main()

{  float meter, mile, feet, inches;

 cout<<"enter meters";

 cin>>meters";

 feet=meter×3.2808;

 mile= meter×0.000621371;

 inches= meter×39.3701;

cout<<"Value of"<<meter<<"meter"<<"in feet is"<<feet<<"feet":

cout<<"Value of"<<meter<<"meter"<<"in mile is"<<mile<<"mile";

cout<<"Value of"<<meter<<"meter"<<"in inches is"<<inches<<"inches";

getch();

}

8 0
3 years ago
What does it mean "Be Proactive"?
joja [24]

Answer:controlling a situation by making things happen or by preparing for possible future problems

Explanation:

4 0
2 years ago
Read 2 more answers
Assume you want to write a code to calculate the addition of two numbers digit by digit. Provide the running time for your algor
Sergio039 [100]

Answer:

Explanation:

Using Python programming language

Explanation:

1. I defined a function add and passed in two parameters (a,b).

2. In the block of the function, I added the two numbers and printed the result.

3. I decided to use a function so that the program is re-usable and can accept various inputs.

Find the code below. (# are used for comments)

#Addition of numbers

def add(a,b):

   print(a+b)

#Test Cases

add(2,4.5)      #Result=6.5

add(10,290)     #Result=300

add(2.567,4.58) #Result=7.147

5 0
3 years ago
Five features of any window​
Vesna [10]

Answer:

The features of any windows are

1. Start menu

2. Notification area or task bar

3. Window snipping tools

4. Using Local Area Networks

5. Windows explorer libraries

Explanation:

8 0
3 years ago
In this lab, you complete a prewritten Python program for a carpenter who creates personalized house signs. The program is suppo
ivolga24 [154]

Using the computer language in python to write a function code that personalized house signs

<h3>Writting the code in python:</h3>

<em>#Assign varibles</em>

<em>charge = 0.00</em>

<em>numChars = 8</em>

<em>color = "gold"</em>

<em>woodType = "oak"</em>

<em />

<em>#Checking for number of characters</em>

<em>if numChars > 5:</em>

<em>charge = 35 + (numChars-5)*4</em>

<em>elif numChars > 0:</em>

<em>charge = 35</em>

<em />

<em>#Checking wood type</em>

<em>if woodType == "oak":</em>

<em>charge += 20</em>

<em />

<em>#Checking for color</em>

<em>if color == "gold":</em>

<em>charge += 15</em>

<em />

<em>#Print output</em>

<em>print("The charge for this sign is $"+str(charge)+".")</em>

See more about python at brainly.com/question/13437928

#SPJ1

5 0
2 years ago
Other questions:
  • What microsoft operating systems started the process of authenticating using password and username
    14·1 answer
  • What happens when your computer is in Hibernate mode?
    12·1 answer
  • If we have a priority queue storing approximately million numbers, and the bottom level is "full", which of the following statem
    9·1 answer
  • Can multiple processors can be installed in a single processor housing?
    14·2 answers
  • What is the output of the following code segment? int n = 0; for (int k = 0; k&lt; 2; k++) {n=n +2;} cout &lt;&lt; n; oo 0 1 O O
    8·1 answer
  • Write a Java program that prompts the user for an int n. You can assume that 1 ≤ n ≤ 9. Your program should use embedded for loo
    5·1 answer
  • How to create an app on app store please its not a joke, if someone knows tell me how
    15·1 answer
  • The first version of Windows to have a Start button and taskbar was?
    5·1 answer
  • What is a key differentiator for Accenture when delivering Artificial Intelligence (AI) solutions to clients?
    11·1 answer
  • Which tab on the ribbon in the folder window allows users to change how the contents of the folder are being shown?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!