C++ Program to find minimum element in given array
Program description :
In this article , we will see how to find smallest element in given array in linear time.
C++ Program to find minimum element in given array
#include<bits/stdc++.h>usingnamespacestd ;
intmain(){
int n , i;
cout<<"Enter the number of elements in array : \n";
cin>>n;
//declaring array of size nint arr[n];
cout<<"Enter the elements of array : \n";for(i=0 ; i < n ; i++)
{
cin>>arr[i];
}
//assuming first element is smallest elementint min = arr[0];
//comparing every element with minimum elementfor(i=1 ; i<n ; i++)
{
if( arr[i] < min )
{
min = arr[i];
}
}
cout<<"Minimum element in given array is "<< min << endl;
}
Comments