How to output the highest number

Hi guys, I think this might sound silly, but im not sure!

I need to know how to output the highest number which is stored in an array? meaning if I have 4 teams playing a game and team 1 got 2, team 2 got 3, team 3 got 0 and team 4 got 1

How could I make my program display the highest numbers??

Thanks for your time guys
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int myArray[] = {2,3,0,1};
	cout << "Highest number in the array is " << *max_element( myArray, myArray + 4 ) << endl;
	return 0;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
int max = 0;
const int teams = 4;
int team[teams];
team[0] = 2;
team[1] = 3;
team[2] = 0;
team[3] = 1;
for(int i = 0; i < teams; i++){
 if(max < team[i]){
  max = team[i];
 }
}
printf("max: %i", max);
Why are you pushing C so much today?
1
2
3
4
5
6
7
8
int tab[] = {6,12,4,67,9,23,5};
	int max = 0;
	for(int i=0;i<7;i++)
	{
		if(tab[i]>max)
			max=tab[i];
	}
	cout<<max;


edit...

woops... JMC was faster :)
Last edited on
I tend to prefer the OP work at the problem a little over just giving him the answer...

The reason professors give homework is to stretch the brain some. Not breed fail.

My $0.02.
I tend to agree, but since this can be solved in 1 line, I didn't think it would be that bad to just give it to him. I'm assuming there is more to this assignment than what he has mentioned here. And now he knows you can use STL algorithms with arrays. It`s been a learning experience.
Topic archived. No new replies allowed.