This example will show you how to find a maximum of elements in an Array using C program.

The below findMax function takes two arguments and returns an integer

int findMax(int *a, int n)

*a – pointer to an array

n – size of the array

Example

#include<stdio.h>

int findMax(int *a, int n){
	int max,i;
	max = a[0];
	for(i=1;i<n;i++){
		if(a[i]>max){
			max = a[i];
		}
	}
	return max;
}

main(){
	int i;
	int size=5;
	int a[5];
	int max;
	for(i=0;i<size;i++){
		a[i]=i+100;
	}
	max = findMax(a,size);
	printf("Maximum value in array is %d",max);
	return;
}

Output

Maximum value in array is 104

Thanks for reading.

I am a professional Web developer, Enterprise Application developer, Software Engineer and Blogger. Connect me on JEE Tutorials Twitter Facebook  Google Plus Linkedin Or Email Me

Leave a Reply

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