Biggest Term

How do you find the biggest term of a series/sequence. Is it possible to find the biggst number of the output of a loop? Can this be done with a FOR loop? or any loop at all? any suggestions?

Basically I'm going to ouput a series of numbers and then say "the highest term is: "

I'm not sure how to do this.
Last edited on
Here's a simple example. You can play around with entering different numbers in various points within the array, and you'll see that it always comes up with the largest.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;

int main()
{
    int myarray[]={7,4,9,3,1,6};
    int bignumber=myarray[0];
    for(int i =0; i<6; i++)
    {
      if(myarray[i]>bignumber)
      {
         bignumber=myarray[i];
      }
    }
cout<<bignumber<<endl;
system("pause");
}
Another way

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <algorithm>
using namespace std;

template< typename T, size_t N >
size_t ArraySize( T (const &)[N] )
{ return N; }

int main()
{
    int myarray[]={7,4,9,3,1,6};
    cout << *max_element( myarray, myarray + ArraySize( myarray ) ) << endl;
}
Topic archived. No new replies allowed.