Largest element in the array:
- Consider the first element of array as largest element initially.
- Continue compare with all other elements in the array from second location.
- If we found an element which is larger than assumed element, replace it.
- Continue this process until array index ends.
- Display the largest element once we found.
#include <stdio.h>
int main()
{
int arr[8] = {7,2,9,14,3,27,5,4};
int large=arr[0], i;
for(i=1 ; i<8 ; i++)
{
if(arr[i]>large)
{
large = arr[i];
}
}
printf("Largest element is : %d \n", large);
return 0;
}