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.

Tags:

I am a professional Web developer, Enterprise Application developer, Software Engineer and Blogger. Connect me on JEE Tutorials | TwitterFacebook Google PlusLinkedin | Reddit | Email Me

Leave a Reply

Your email address will not be published. Required fields are marked *