Solved

Finding the element of an array with the highest value

Posted on 2000-03-09
1
208 Views
Last Modified: 2010-04-02
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
Comment
Question by:mm162
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 25 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maze travler 6 55
Lambda for random numbers problem 7 112
how to convert c++ code to Android App 3 95
sorting efficency of sorting algorithm 30 113
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question