Thread: Easiest way to find the max value stored in an array

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    56

    Easiest way to find the max value stored in an array

    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];
       }
    }
    Last edited by criticalerror; 01-21-2004 at 07:41 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help finding the max and min of a 2d array
    By finalreign in forum C Programming
    Replies: 6
    Last Post: 04-29-2009, 11:39 AM
  2. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 09:51 AM
  3. Hex digits stored in char array.
    By Kevinmun in forum C Programming
    Replies: 8
    Last Post: 11-18-2005, 04:05 PM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. finding max values in an array
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 01-29-2002, 02:47 PM