Online Snippets Library

Create C Program to find the largest element of an array

To Findout largest element of array,We need to iterate array and check each element of an array if it is the largest Or Not. Complete Program is given below.

C Program
#include <stdio.h>

int main() {
   int array[5] = {1, 2, 3, 4, 10};
   int loop, largest;

   largest = array[0];
   
   for(loop = 1; loop < 5; loop++) {
      if( largest < array[loop] ) 
         largest = array[loop];
   }
   
   printf("Largest element of array is %d", largest);   
   
   return 0;
}

Output

Largest element of array is 10.