Easy Tutorial
❮ C Standard Library C Function Remove ❯

C Language Example - Finding the Smallest Element in an Array

C Language Examples

Use a for loop to iterate through the elements, starting from the first element and comparing each one to find the smallest element:

Example

#include <stdio.h>

int main() {
   int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
   int loop, smallest;

   smallest = array[0];

   for(loop = 1; loop < 10; loop++) {
      if( smallest > array[loop] ) 
         smallest = array[loop];
   }

   printf("The smallest element is %d", smallest);   

   return 0;
}

Output:

The smallest element is 0

C Language Examples

❮ C Standard Library C Function Remove ❯