C++ Program to Find Largest Number in an Array

In this program, you will learn to find largest number in an Array. An array is a collection of homogeneous (same type) data items stored in contiguous memory locations. For example if an array is of type "int", it can only store integer elements and cannot allow the elements of other types such as double, float, char etc.



Source Code
#include<iostream>
using namespace std;

int main()
{
    int a[5], i, max;
    cout<<"Enter 5 array elements\n";
    for(i=0; i<5; i++)
        cin>>a[i];

    max = a[0];
    for(i=1; i<5; i++)
    {
        if(max < a[i])
            max = a[i];
    }
    cout<<"Largest element is "<<max;
    return 0;
}
Output
Enter 5 array elements
75
25
68
43
80
Largest element is 80