1#include <iostream>
2using namespace std;
3int main(){
4 //n is the number of elements in the array
5 int n, largest;
6 int num[50];
7 cout<<"Enter number of elements you want to enter: ";
8 cin>>n;
9
10 /* Loop runs from o to n, in such a way that first
11 * element entered by user is stored in num[0], second
12 * in num[1] and so on.
13 */
14 for(int i = 0; i < n; i++) {
15 cout<<"Enter Element "<<(i+1)<< ": ";
16 cin>>num[i];
17 }
18 // Storing first array element in "largest" variable
19 largest = num[0];
20 for(int i = 1;i < n; i++) {
21 /* We are comparing largest variable with every element
22 * of array. If there is an element which is greater than
23 * largest variable value then we are copying that variable
24 * to largest, this way we have the largest element copied
25 * to the variable named "largest" at the end of the loop
26 *
27 */
28 if(largest < num[i])
29 largest = num[i];
30 }
31 cout<<"Largest element in array is: "<<largest;
32 return 0;
33}