Program to find Smallest element in an array using C

Smallest Element in an array

Today we will find smallest or minimum element in an array using C concept.We apply algorithm that assumes the first element as smallest element and then compare it with other elements if an element is smaller than it then, it becomes the new smallest element, and this process is repeated till complete array is scanned.
For Example:- 

Input:- {5,2,9,15,6},input from the user
Output:- {2},smallest element in an array
Here we have given a solution of this query in C Programming.

Smallest-Element-in-an-Array

Working:-

We can find smallest element in an array by following these steps:-

  1. Initialize the required variables.
  2. Take the input from user.
  3. Assume smallest element is present at first position.
  4. Scan each element through a for loop.
  5. Check if element Scanned is new smaller than small.
  6. If it is smallest than small, change the value of small with that element.
  7. Print small as it stores the smallest element of array.
Competitive Coding Techniques

C Program:-

//C Code to find smallest element in an array
#include<stdio.h>
int main() 
    {
        int a[50], p, num, smallest;
        printf("Enter the size of array :");    // Take size of array
        scanf("%d", &num);
        printf("Enter the elements of array : \n");
        for (p = 0; p < num; p++)   //Read elements of an array
        scanf("%d", &a[p]);
        smallest = a[0];    //Let first element as smallest
        for (p = 0; p < num; p++)
        {
            if (a[p] < smallest) 
            {
            smallest = a[p];
            }
        }
        printf("Smallest Element of an array : %d", smallest);  // Print smallest element
        return (0);
    }
Output:-
Enter the size of array : 6
Enter the elements of array : 
2
0
8
44
6
17
Smallest Element of an array : 0
Competitive Coding Techniques

One comment on “Program to find Smallest element in an array using C”


  • Ankit

    In short if we gave to code this. Here is the code
    import numpy as np
    a= np.array([10,9,4,6,20,25])
    print(a.min())