**Discussion 3**
09/08, 09/10
[(back to course webpage)](./mcs360_fall2020.html)
# Problem 1
Write a CPP program that asks the user to input a number $n$, and then input $n$ integers $a_0,\ldots,a_{n-1}$. Store these integers in a `std::vectorHint 1
This is how you would take the input:
~~~~~~~~cpp
int main() {
int n;
std::cout << "Enter n: ";
std::cin >> n;
std::vectorHint 2
We can find the largest in the array by the following algorithm:
**********************************************************************************************************************************************
*|100|200| 30| 50| 70| |100|200| 30| 50| 70| |100|200| 30| 50| 70| |100|200| 30| 50| 70| *
* ^ ^ ^ ^ *
* | -> | -> | -> ... -> | *
* i=0 i=1 i=2 i=4 *
* (initial) (100 < 200) (200 > 30) (200 > 70) *
* l=100 l=200 l=200 l=200 *
**********************************************************************************************************************************************
Solution
~~~~~~~~~~cpp
#include Remark
There is also a standard library function called `std::max_element` in `algorithm.h` that lets you do this in a click, but it does exactly what we did here.
Check [here](https://www.cplusplus.com/reference/algorithm/max_element/) for the details.
Hint 1
You can look up the rolling die problem done in lecture. It tells you how to compute the frequency of every element.