C Program to Find the Maximum and Minimum in an Array - Source Code, Output & Execution Flow

C Program to Find the Maximum and Minimum in an Array

This C program finds both maximum and minimum values in an array.

#include <stdio.h>
int main() {
    int a[] = {8, 3, 15, 1, 9};
    int i, max = a[0], min = a[0];
    for (i = 1; i < 5; i++) {
        if (a[i] > max) max = a[i];
        if (a[i] < min) min = a[i];
    }
    printf("Maximum = %d, Minimum = %d
", max, min);
    return 0;
}
Maximum = 15, Minimum = 1

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.

Sai Kishore Randhi, author
About the author

Sai Kishore Randhi

Embedded systems, VLSI, and chip design

Sai Kishore writes about embedded systems, VLSI, chip design, and the programming concepts behind modern hardware.

View LinkedIn profile ↗