answersLogoWhite

0


Best Answer

#include

using std::cout;

using std::endl;

double maxValue(double arr, const intarrSize);

int main()

{

const int arrSize = 10;//Size of the array you are going to use

double arr[arrSize] = {0.0};

cout << endl << "Enter the array elements..."

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

{

cout << endl << "Enter " << (i + 1) << " element:";

cin >> arr[i];

}

cout << endl << "Max value is: " << maxValue;

system("PAUSE");

return 0;

}

double maxValue(double arr, const intarrSize)

{

double max = arr[0];

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

{

if ( max < arr[j])

{

max = arr[j];

}

}

return max;

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

#include

#include

#include

template

class numbers : public std::vector

{

// uses compiler-generated constructors,

// destructor and assignment operator

// for brevity.

public:

const T get_greatest() const;

};

template

const T numbers::get_greatest() const

{

std::vector::const_iterator it = begin();

T greatest = *it;

while( ++it != end() )

if( greatest < *it )

greatest = *it;

return( greatest );

}

int main()

{

// seed the pseudo-random number generator

std::srand((unsigned) time(NULL));

// initialise array with random integers

numbers nums;

std::cout<<"Array of numbers:\n"<

for( size_t num=0; num<10; ++num )

{

nums.push_back( rand() );

std::cout<

}

std::cout<<"\nThe largest number is: "<

}

Output

Array of numbers:

21238

5668

10199

10743

25376

2426

12192

1408

12055

25632

The largest number is: 25632

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the c plus plus program that finds max value in the array of size n?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Array implementation of priority queue example program in c plus plus?

yes


Would you Write c plus plus program using array for Fibonacci number?

You can write a C++ fib pro using arrays but the problem is the prog becomes very complicated since u need to pass the next adding value in an array.....


Can you help me with the C plus plus code of the program which has 10 index of array it adds 5 into every even elements of the array and then it subtracts 10 into the odd elements of the array?

int array[10] = {...}; for (int i = 0; i &lt; 10; ++i) { if (i % 2 == 0) array[i] += 5; else array[i] -= 10; }


C plus plus program that finds the minimum number?

template&lt;typename T&gt; size_t min(const T a[], const size_t size) { // assume first element (index 0) has the smallest value size_t selected=0; // scan remainder of array looking for anything smaller than selected for (size_t right=selected+1; right&lt;size; ++right) if (a[right]&lt;a[selected]) selected=right; return a[selected]; }


How calculate the average scored by student for is subject in c plus plus program?

Put all the values in an array, iterate through the array with a for loop, sum all the values, then divide by the count of the values.


What will be the Flowchart for adding all elements in an array in c plus plus?

It is not possible to show a flowchart in this website -- it is text only. The algorithm can be summarised as follows: int sum(std::array&lt;int&gt;&amp; a) { int sum = 0; // initialise the return value for (auto i : a) // for each value in the array sum += i; // increment the sum by the value return sum; // return the sum }


What is the lowest subscript of an array in c plus plus?

The lowest subscript of an array in C, or C++ is 0.


How do you declare a string array and add elements to it in C plus plus?

You cannot add elements to a fixed array in C or C++. If, however, the array is declared as a pointer to an array, you can add elements by allocating a new array, copying/adding elements as needed, reassigning the new array to the pointer, and deallocating the original array.


How do you write a program in c plus plus to check if an array is symmetric?

To determine if an array is symmetric, the array must be square. If so, check each element against its transpose. If all elements are equal, the array is symmetric.For a two-dimensional array (a matrix) of order n, the following code will determine if it is symmetric or not:templatebool symmetric(const std::array& matrix){for (size_t r=0 ; r


To find the largest element of an array in c plus plus?

int GetMaxElement( void * array) { if (array != 0) { return(max(array[], typeof(array))); } return(0); }


What is array in C languange?

An array is a contiguous block of data in memory. When you declare an array in C you need to give it a type and a name (like a normal variable), plus you need to give it a size. // normal integer variable x int x; // array of 10 integers int x[10]; Remember that the variable x is actually just a pointer, or reference, to a point in memory. This point in memory is the start of the array, so the value at x[0] is the first value in the array, x[1] is the second, and so on. Also remember that C has no bounds checking, so you can, indeed, read any value past the maximum. x[3474] would return an integer value, but it's going to be some part of memory that is not in your array. Attempting to change this value could result in something very bad happening.


C plus plus program calculate the power value of input base and exponent numbers?

cn = c0 *( 1 + i ) pow n