Find minimum of elements in Array
This example will show you how to find a minimum of elements in an Array using C program.
The below findMin function takes two arguments and returns an integer
int findMin(int *a,int n)
*a – pointer to an array
n – size of the array
Example
#include<stdio.h>
int findMin(int *a, int n){
int min,i;
min = a[0];
for(i=1;i<n;i++){
if(a[i]<min){
min = a[i];
}
}
return min;
}
main(){
int i;
int size=5;
int a[5];
int min;
for(i=0;i<size;i++){
a[i]=i+100;
}
min = findMin(a,size);
printf("Minimum value in array is %d",min);
return;
} Output
Minimum value in array is 100
Thanks for reading.
No comments
Leave a comment