Entry
C++: Array: Maximum: How to find the maximum in array? Dimension: 1: Standard Template Library (STL)
Feb 22nd, 2006 07:37
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 22 February 2021 - 02:57 pm -------------------
C++: Array: Maximum: How to find the maximum in array? Dimension: 1:
Standard Template Library (STL)
--- cut here: begin --------------------------------------------------
#include <iostream>
//
#include <vector.h>
//
using namespace std;
//
int main() {
//
// --- Declare a vector.
//
vector <double> v;
//
// --- Read numbers into it.
//
v.push_back( 1 );
v.push_back( 2 );
v.push_back( 3 );
v.push_back( 4 );
v.push_back( 5 );
v.push_back( 6 );
//
// --- Search for maximum value
//
double maxValue = v[ 0 ];
//
for ( int I = 0; I <= v.size() - 1; I++ ) {
if ( maxValue < v[ I ] ) {
maxValue = v[ I ];
}
}
cout << "maximum = ";
cout << maxValue;
cout << endl;
//
}
--- cut here: end ----------------------------------------------------
===
Internet: see also:
---
Computer: Language: Compiler: C++: Array: Link: Can you give an
overview of links?
http://www.faqts.com/knowledge_base/view.phtml/aid/39794/fid/163
----------------------------------------------------------------------