What is the easiest way to find the maximum value stored in an array and display it on the screen...
Here's what I worked out, don't know if it works, because I don't have a compiler installed on this computer...
Code:#include <iostream> using namespace std; void MaxElement (int Array [], int& Max); const int ArraySize = 3; int main (void) { int max; int Array [3]; Array [0] = 102; Array [1] = 230; Array [2] = 191; max = Array [0]; MaxElement (Array, max); cout << "Max Value: " << max << endl; return 0; } void MaxElement (int Array [], int& max) { for (int i = 1; i < ArraySize; i ++) { if (Array [i] > max) max = Array [i]; } }



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.