Find Minimum Value of an Array in C

Beginner
⏱️ 9 min read
📚 Updated: May 2026
🎯 2 Code Examples
Arrays

What you’ll learn

  • What “minimum” means for a list of numbers, without assuming you already code every day.
  • The usual one-pass trick: remember the best answer so far and update it when you see something smaller.
  • A small reusable function find_min, counting elements with sizeof, and int main(void).
  • A second example where every value is negative, plus a live preview that uses the same numbers as example 1.

Overview

Picture a row of numbers on the board. To find the smallest, you can walk from left to right and keep the best (“smallest so far”) in your head. A computer does the same with a variable—no sorting, no magic.

Two programs

A mixed list (answer 2) and a list of only negatives (answer −9).

Live preview

Try the button: it uses the same eight integers as example 1.

Interview hook

Say O(n) time, O(1) extra space, and mention empty arrays if the interviewer asks.

Prerequisites

for loops, arrays, and printf.

  • #include <stdio.h> and a simple array like int a[] = { ... }.
  • Optional but handy: sizeof(array) / sizeof(array[0]) tells you how many slots the array has when you did not hard-code the length.

The idea

Start by treating the first number as the smallest you have seen. For each next number, ask: “Is this smaller than what I am holding?” If yes, replace your answer. After you visit every position, what you hold is the minimum for the whole array.

One loop, one variable—easy to follow on paper and in an interview.

Live preview

Same eight integers as example 1: 12, 5, 7, 3, 2, 8, 10.

Runs the same comparison logic in JavaScript in your browser (no compile needed).

Live result
Press “Find minimum”.

Algorithm

Goal: return the smallest value among n integers stored one after another in memory (a C array).

Check length

For this tutorial, assume size >= 1. If the length can be zero, handle that before you read arr[0].

Initialize

Set min = arr[0].

Scan

For i from 1 to size - 1, if arr[i] < min, set min = arr[i].

Return

Return min.

📜 Pseudocode

Pseudocode
function find_min(arr, size):   // assume size >= 1
    min ← arr[0]
    for i from 1 to size - 1:
        if arr[i] < min:
            min ← arr[i]
    return min
1

Find minimum (reference program)

Matches the classic interview shape: a helper find_min, a sample array, and length from sizeof. Uses int main(void). The sample matches the old walkthrough: minimum is 2.

c
#include <stdio.h>

int find_min(const int arr[], int size) {
    int min_val = arr[0];

    for (int i = 1; i < size; ++i) {
        if (arr[i] < min_val) {
            min_val = arr[i];
        }
    }

    return min_val;
}

int main(void) {
    int array[] = {12, 5, 7, 3, 2, 8, 10};
    int size = (int)(sizeof(array) / sizeof(array[0]));
    int min_value = find_min(array, size);

    printf("Minimum value in the array: %d\n", min_value);

    return 0;
}

Explanation

const int arr[] tells the reader (and the compiler) that this function will not change the array through arr. The cast on sizeof keeps size as int here; for huge arrays in real code, size_t is often nicer.

2

When every element is negative

Smallest still means “leftmost on the number line.” Here the minimum is −9, not −1.

c
#include <stdio.h>

int find_min(const int arr[], int size) {
    int min_val = arr[0];
    for (int i = 1; i < size; ++i) {
        if (arr[i] < min_val) {
            min_val = arr[i];
        }
    }
    return min_val;
}

int main(void) {
    int negatives[] = {-9, -3, -1, -7};
    int n = (int)(sizeof(negatives) / sizeof(negatives[0]));

    printf("Minimum (most negative): %d\n", find_min(negatives, n));

    return 0;
}

Notes

Parallel systems. You can split the array, find each part’s minimum, then take the minimum of those—same idea as parallel max, but with smaller-is-better.

Floating-point. The same loop works with double; in numerical code be careful with NaN and with comparing floats for exact equality.

❓ FAQ

It is the smallest number in the list. If you wrote all values on a line, it is the one farthest to the left on the number line (the most negative, or the smallest positive if everything is positive).
You need a first guess taken from the data. The first slot is a fair starting point. Then each later number can replace that guess if it is smaller.
With zero elements there is no smallest value. Real programs should check the length first and avoid reading arr[0]. This lesson assumes at least one element so the idea stays simple.
Yes. You still begin with the first element. Smaller means closer to negative infinity, so among {-9, -3, -1} the answer is -9.
That is fine. You still print that value once; duplicates do not change which number is smallest.
No. Sorting costs more work than one scan. To find only the minimum, walking the array once is enough.
You look at each of the n items once: O(n) time and O(1) extra space besides the array itself.

🔄 Input / output

These programs use fixed numbers inside the code. To read values from the keyboard, you would use scanf in a loop, fill an array, then call find_min with the count you read.

Edge cases

Empty

size == 0

There is no minimum; do not access arr[0] until you know the length is at least one.

One element

size == 1

The loop never runs; min_val stays that single element, which is correct.

⏱️ Time and space complexity

ApproachTimeExtra space
Single scanO(n)O(1)

Summary

  • Algorithm: keep a running minimum while scanning once.
  • Cost: O(n) time, O(1) extra space.
  • Edge: decide what to do when n = 0.
Did you know?

Finding the smallest value in an unsorted list still takes a single left-to-right pass: O(n) time and O(1) extra memory. You cannot do better in the worst case without extra structure, because any unseen element could be the new minimum.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful