Function that returns the maximum value of the array

Assignment Help C/C++ Programming
Reference no: EM13939623

Arrays are collections of elements of the same type. The elements of the array can be accessed using their position (index) in the array. Arrays may have several dimensions: they can be similar to lists (1-dimension), matrices (2-dimensions), cubes (3-dimensions) etc.

1. The first exercise involves a 1-dimensional array of integers and uses a function that returns the maximum value of the array. The program is not completely defined, the ?? should be replaced with the corresponding expressions in order to get the program work correctly.

Here is the program

#include <iostream>

using namespace std;

//declares the size of the array as a constant integer

const int SIZE = 10;

//declares the function that computes the maximum value

//the function returns an integer and has an array of integers as parameter

int max(int a[]);

int main()

{

//declares the array of integers having the size SIZE

int arrayone[SIZE];

int max_value;

//initializes each element of the array with the value of its index+1

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

arrayone[i] = i+1;

//call here the function that returns the maximum value

max_value = ??;

cout <<"The maximum element of the array is "<< max_value <<endl;

return(0);

}

int max(int a[])

{

int maximum;

//compare each element with maximum and assign its value to maximum if //greater

for (int i=??; i<??; i++)

{

if (maximum < a[i])

maximum = a[i];

}

return(maximum);

}

2. The second program declares a bi-dimensional array and uses a function to compute the sum of the elements on the main diagonal (with index [ii]). Again, the program is not completely defined, you have to replace the ?? in order to get a compilable version.

Here is the program:

#include <iostream>

using namespace std;

//declares the size of te array as a constant integer

const int SIZE = 10;

//declares the function that returns the sum of

// the elements on the main diagonal

int sum(int a[SIZE][SIZE]);

int main()

{

//declares the array of integers

int arraytwo[SIZE][SIZE];

int s;

//initializes each element of the array with the sum of its indexes

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

for(int j = 0; j<SIZE; j++)

arraytwo[i][j] = i+j;

//call here the function that returns the sum of the main diagonal elements

s = ??

cout <<"The sum of the main diagonal elements is "<< s <<endl;

return(0);

}

int sum(int a[SIZE][SIZE])

{

int s=0;

//compute the sum of elements on main diagonal

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

{

s = ??

}

return(s);

Reference no: EM13939623

Questions Cloud

Expected return-market risk premium-reward-to-risk ratios : Stock Y has a beta of 1.4 and an expected return of 15.1 percent. Stock Z has a beta of .7 and an expected return of 8.6 percent. If the risk-free rate is 5 percent and the market risk premium is 6.5 percent, the reward-to-risk ratios for stocks Y an..
Describe the strategic planning process : Briefly describe the strategic planning process and how you would use this to promote the aims and outcomes of the program.
Problem regarding the center-line vaporization : A string of negligible diameter is drawn down the center-line of a pipe containing a Newtonian fluid. At what velocity, w, must the string be drawn in order to vaporize the fluid? Pose the problem in a general fashion but make whatever reasonable ..
How would it affect urine ph and why would this change occur : While visiting your family, you come down with a severe case of stomach flu. You begin vomiting and continue vomiting for more than a day, unable to keep any food or fluids down. How would you expect your condition to affect your blood pH and why ..
Function that returns the maximum value of the array : Arrays are collections of elements of the same type. The elements of the array can be accessed using their position (index) in the array.
Compute the roi for the division without the investment : Compute the ROI for the division without the investment. Compute the ROI for the division with the new investment. Do you think the division manager will approve the investment?
Challenges that health care leaders are faced : Critically discuss some of the challenges that health care leaders are faced with in terms of decision making within the team environment. Explore this specifically in relation to to the aged care sector and disability health services.
What is the expected return of gell stock : Suppose Blek stock has a beta of 1.7, whereas Gell stock has a beta of 0.96. If the risk free interest rate is 4.2% and the expected return of the market portfolio is 13.4%, according to the CAPM, What is the expected return of Blek stock? What is th..
How can she make antiserum specific for rabbit igg : Suppose a scientist wants to make antiserum specific for IgG. They inject a RABBIT with purified MOUSE IgG and get an antiserum thats reacts with MOUSE IgG and other mouse isotopes. Why did this happen? How can she make antiserum specific for RABB..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd