Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Finding the element of an array with the highest value

Posted on 2000-03-09
Medium Priority
230 Views
In other words, suppose you have declared a variable:
float Array[10]
And suppose the elements of the array have been assigned some random numbers.
I am looking for code that can identify which element of the array has the highest value.  That is, in math notation, I need to get a number j between 0 and 9 such that Array[j] is the highest value assumed by any element in the array.
0
Question by:mm162
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
1 Comment

LVL 86

Accepted Solution

jkr earned 100 total points
ID: 2602233
float Array[MAX_ARRAY];

int nHighestIdx = 0;
float fHighestVal = 0.0;

//...

for ( int i = 0 ; i < MAX_ARRAY; i++)
{
if ( Array [ i] > fHighestVal)
{
fHighestVal = Array [ i];
nHighestIdx = i;
}
}

When the loop terminates, 'nHighestIdx' contains the array index of the highest value in the array...
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
###### Suggested Courses
Course of the Month11 days, 12 hours left to enroll