C Program to Find Largest Element in an Array

This post helps to find largest element in an array using the C programming language.

C Program to Find Largest Element in an Array

#include <stdio.h>
int main() 
{
   int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
   int loop, largest;
   largest = array[0];
   for(loop = 1; loop < 10; loop++) 
   {
      if( largest < array[loop] ) 
         largest = array[loop];
   }
   printf("Largest element of array is %%d", largest);   
   return 0;
}

Output

Explanation

In this program, we find the largest array by initializing array values and variables like loop and largest. The array values will be stored in the variable namely largest.

	int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
   	int loop, largest;
   	largest = array[0];

Here we use the for loop condition and if condition. For loop condition is used for verifying whether the given condition is satisfying or not and If condition is used as a method to check the calculation of For loop condition.

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

After the following checking and calculation part is completed. We now proceed to the output.