C Program to Find the Largest Element in an Array - Source Code, Output & Execution Flow

C Program to Find the Largest Element in an Array

This C program finds the largest element in an array by comparing each value.

#include <stdio.h>
int main() {
    int a[] = {12, 45, 7, 89, 23};
    int i, largest = a[0];
    for (i = 1; i < 5; i++) {
        if (a[i] > largest) largest = a[i];
    }
    printf("Largest element = %d
", largest);
    return 0;
}
Largest element = 89

In this program, the input is read first when required, the core logic is applied step by step, and the final result is displayed using printf(). Follow the execution flow beside the code to understand how each statement contributes to the output.