This is a c program to find the largest element from an array. We have used the for loop and if… statement to achieve the program goal. In this program, firstly the user will enter the number of array elements and then the numbers of elements. On the basis of entered array elements, we will find the largest number and displays as output.
Copy the below c program and execute it with the help of c compiler. We have executed this program and added the program output at the below of this page.
int i, n;
printf("Enter the number of elements between(1-100):");
// Stores number entered by the user
for(i = 0; i < n; ++i)
printf("Enter Number %d: ", i+1);
// Loop to store largest number to arr
for(i = 1; i < n; ++i)
// Change < to > if you want to find the smallest element
if(arr < arr[i])
arr = arr[i];
printf("The largest element: %.2f", arr);
Enter the number of elements between(1-100): 5
Enter Number 1: 8
Enter Number 2: 5
Enter Number 3: 6
Enter Number 4: 3
Enter Number 5: 19
The largest element is: 19.00
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: array in c, array in c language, c program, c program examples, c program examples with output, c programs, c programs with solutions, find largest element of an array in c, largest number from an array, list of important c programs