Program to find largest element in an array

In this example, we declare array and find largest element of that array.

C Program to Find Largest Element in an Array

#include <stdio.h> 
int largest(int arr[], int n)
    int i;   
    int max = arr[0];
    for (i = 1; i < n; i++)
        if (arr[i] > max)
            max = arr[i];
    return max;
int main()
    int arr[] = {10, 324, 45, 90, 80};
    int n = sizeof(arr)/sizeof(arr[0]);
    printf("Largest in given array is %d", largest(arr, n));
    return 0;

Output :

Largest in given array is 324

Share your thoughts

Ask anything about this examples