problems with finding Max

I don't really have a code to input-
my major problem is that I am trying to find the max number of 10 inputs. so far I know that the user is going to input 10 numbers and store them into an array I just have no clue on how to get the biggest number of the inputs. I just need a general point in the right direction. or a code example something I can see and dissect to understand what I am doing wrong.

Thanks so much!

closed account (2UD8vCM9)
An example of how to use a nested for loop to sort an array of integers with 4 elements from smallest to largest.

1
2
3
4
5
int numbers[4] = { 6, 1, 3, 0 };
for (int i = 0; i < 4; i++)
	for (int j = i+1; j < 4; j++)
		if (numbers[i] > numbers[j])
			swap(numbers[i], numbers[j]);


numbers[0] = smallest integer
numbers[3] = largest integer
Last edited on
oh wow! Thanks! that actually helped a ton. Why I can't just google that I have no idea. This helps tremendously!
Another way of minding the Max is this -

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int x[10];

	for (int i = 0; i < 10; i++)
	{
		cout << "Enter #" << i + 1 << endl;
		cin >> x[i];
	}

	int max = x[0];

	for (int i = 0; i < 10; i++)
	{
		if (x[i] > max)
		{
			max = x[i];
		}
	}

	cout << max << endl;
Topic archived. No new replies allowed.