Largest element in an array

Description:

Get n number of elements of an array from the user and find the largest number in the array Test Case 1 Input (stdin) 4 4 3 2 1 Expected Output Largest element=4 Test Case 2 Input (stdin) 6 1 2 3 4 5 6 Expected Output Largest element=6

Program :

#include <iostream>

using namespace std;

int main(){

   int n, largest;

   int num[50];

   cin>>n;

   for(int i = 0; i < n; i++)

      cin>>num[i];

   largest = num[0];

   for(int i = 1;i < n; i++) {

      if(largest < num[i])

         largest = num[i];

   }

   cout<<"Largest element="<<largest;

   return 0;

}