How to find the largest (max) element in one dimensional int array in C

1 Answer

0 votes
#include <stdio.h>

#define LEN 10

int main(void)
{
	int arr[] = { 2, 234, 48, 17, 98, 918, 800, 12237, 100, 28 };
	int max;
	
	max = arr[0];
 
	for (int i = 1; i < LEN; i++) 
		if (arr[i] > max) max = arr[i];
		
	printf("Largest Element : %d\n", max);
    
	return 0;
}
  
    
/*
      
run:

Largest Element : 12237

*/

 



answered Feb 3, 2016 by avibootz
edited Feb 3, 2016 by avibootz
...